runfile 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/runfile/dsl.rb +7 -1
- data/lib/runfile/runner.rb +41 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87351dfdba90ed54e90de8659791d79242b993ee
|
4
|
+
data.tar.gz: d0fea602beebde2f9f47d754ceddcd9961d16bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01b40937adcc3301f2afe3143a7f85bae625a19c95a631d7f11774b4aca28328fe9f6dc738eeebc2b6c0dd43e0b13408111721d3eb62e23ea64e0acb782e4096
|
7
|
+
data.tar.gz: 06d21eab94577ec842795941c335621d198162965e30e2e49b079aebab2fae9ef159a5fd6064e9cbab9e57a3813ada6324fd7f700dcfae5a34f857379621c0e0
|
data/lib/runfile/dsl.rb
CHANGED
@@ -35,7 +35,13 @@ module Runfile
|
|
35
35
|
Runner.instance.add_action name, &block
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
# Define a new command namespace
|
39
|
+
def command(name=nil)
|
39
40
|
Runner.instance.namespace = name
|
40
41
|
end
|
42
|
+
|
43
|
+
# Cross-call another action
|
44
|
+
def call(command_string)
|
45
|
+
Runner.instance.cross_call command_string
|
46
|
+
end
|
41
47
|
end
|
data/lib/runfile/runner.rb
CHANGED
@@ -9,7 +9,7 @@ module Runfile
|
|
9
9
|
|
10
10
|
@@instance = nil
|
11
11
|
|
12
|
-
# Initialize all variables to
|
12
|
+
# Initialize all variables to sensible defaults.
|
13
13
|
def initialize
|
14
14
|
@last_usage = nil
|
15
15
|
@last_help = nil
|
@@ -28,7 +28,7 @@ module Runfile
|
|
28
28
|
|
29
29
|
# Load and execute a Runfile call.
|
30
30
|
def execute(argv)
|
31
|
-
File.exist? 'Runfile' or
|
31
|
+
File.exist? 'Runfile' or handle_no_runfile argv
|
32
32
|
load 'Runfile'
|
33
33
|
@@instance.run *argv
|
34
34
|
end
|
@@ -57,14 +57,26 @@ module Runfile
|
|
57
57
|
def run(*argv)
|
58
58
|
action = find_action argv
|
59
59
|
begin
|
60
|
-
|
61
|
-
action or abort "Runfile error: Action not found"
|
62
|
-
@actions[action].execute args
|
60
|
+
docopt_exec action, argv
|
63
61
|
rescue Docopt::Exit => e
|
64
62
|
puts e.message
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
66
|
+
# Invoke action from another action. Used by the DSL's #call
|
67
|
+
# function. Expects to get a single string that looks as if
|
68
|
+
# it was typed in the command prompt.
|
69
|
+
def cross_call(command_string)
|
70
|
+
argv = command_string.split /\s(?=(?:[^"]|"[^"]*")*$)/
|
71
|
+
action = find_action argv
|
72
|
+
begin
|
73
|
+
docopt_exec action, argv
|
74
|
+
rescue Docopt::Exit => e
|
75
|
+
puts "Cross call failed: #{command_string}"
|
76
|
+
abort e.message
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
68
80
|
private
|
69
81
|
|
70
82
|
# Dynamically generate the docopt document.
|
@@ -73,6 +85,16 @@ module Runfile
|
|
73
85
|
maker.make
|
74
86
|
end
|
75
87
|
|
88
|
+
# Call the docopt parser and execute the action with the
|
89
|
+
# parsed arguments.
|
90
|
+
# This should always be called in a begin...rescue block and
|
91
|
+
# you should handle the Docopt::Exit exception.
|
92
|
+
def docopt_exec(action, argv)
|
93
|
+
args = Docopt::docopt(docopt, version: @version, argv:argv)
|
94
|
+
action or abort "Runfile error: Action not found"
|
95
|
+
@actions[action].execute args
|
96
|
+
end
|
97
|
+
|
76
98
|
# Inspect the first two arguments in the argv and look for
|
77
99
|
# a matching action or command_action.
|
78
100
|
# We give priority to the second form (:make_jam) in order to
|
@@ -89,5 +111,19 @@ module Runfile
|
|
89
111
|
end
|
90
112
|
return false
|
91
113
|
end
|
114
|
+
|
115
|
+
# Handle the case when `run` is called without a Runfile
|
116
|
+
# present. We will let the user know they can type `run make`
|
117
|
+
# to create a new sample Runfile.
|
118
|
+
def handle_no_runfile(argv)
|
119
|
+
if argv[0] == "make"
|
120
|
+
sample = File.dirname(__FILE__) + "/../../examples/template/Runfile"
|
121
|
+
dest = Dir.pwd + "/Runfile"
|
122
|
+
File.write(dest, File.read(sample))
|
123
|
+
abort "Runfile created."
|
124
|
+
else
|
125
|
+
abort "Runfile not found.\nUse 'run make' to create one."
|
126
|
+
end
|
127
|
+
end
|
92
128
|
end
|
93
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|