runfile 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/runfile/docopt_helper.rb +18 -1
- data/lib/runfile/dsl.rb +5 -0
- data/lib/runfile/runner.rb +16 -10
- data/lib/runfile/version.rb +1 -1
- 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: 7b0ef66864e2ac38cb60c3c8f78b0641143ebe67
|
4
|
+
data.tar.gz: 73af9361c6dee752c2d819b4215326e890782cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b59e0ae90280031242a8b10f5705538a45a644d239c200429867aa9d1f717c6f992abad6e3fd249aca8fb4d65408268b46d2147fbed60071012535afeda48bd
|
7
|
+
data.tar.gz: 78e11e620be2aace4511e0402b2fe2c228374de9f11601716fd18cfcf0d075942b834bbdb2cdd8627351c5f2360a164a80bcbca844db3adb286fde2232d0737a
|
@@ -16,13 +16,14 @@ module Runfile
|
|
16
16
|
# The superspace argument will be the name of runfile, in case we
|
17
17
|
# are running a named.runfile. It is only needed to generate the
|
18
18
|
# proper `run superspace (-h|--help|--version)` line
|
19
|
-
def initialize(superspace, name, version, summary, actions, options)
|
19
|
+
def initialize(superspace, name, version, summary, actions, options, examples)
|
20
20
|
@superspace = superspace
|
21
21
|
@name = name
|
22
22
|
@version = version
|
23
23
|
@summary = summary
|
24
24
|
@actions = actions
|
25
25
|
@options = options
|
26
|
+
@examples = examples
|
26
27
|
end
|
27
28
|
|
28
29
|
# Generate a document based on all the actions, help messages
|
@@ -35,6 +36,7 @@ module Runfile
|
|
35
36
|
doc += docopt_usage
|
36
37
|
doc += docopt_commands width
|
37
38
|
doc += docopt_options width
|
39
|
+
doc += docopt_examples width
|
38
40
|
doc.join "\n"
|
39
41
|
end
|
40
42
|
|
@@ -86,6 +88,21 @@ module Runfile
|
|
86
88
|
doc
|
87
89
|
end
|
88
90
|
|
91
|
+
# Return all docopt lines for the 'Examples' section
|
92
|
+
def docopt_examples(width)
|
93
|
+
return [] if @examples.empty?
|
94
|
+
|
95
|
+
doc = ["Examples:"]
|
96
|
+
base_command = @superspace ? "run #{@superspace}" : "run"
|
97
|
+
@examples.each do |command|
|
98
|
+
helpline = " #{base_command} #{command}"
|
99
|
+
wrapped = word_wrap helpline, width
|
100
|
+
doc << "#{wrapped}"
|
101
|
+
end
|
102
|
+
doc
|
103
|
+
end
|
104
|
+
|
105
|
+
|
89
106
|
# Call the docopt handler, which will either return a parsed
|
90
107
|
# arguments list, or halt execution and show usage.
|
91
108
|
def args(argv)
|
data/lib/runfile/dsl.rb
CHANGED
@@ -35,6 +35,11 @@ module Runfile
|
|
35
35
|
Runner.instance.add_option flag, text, scope
|
36
36
|
end
|
37
37
|
|
38
|
+
# Set an example command (can be called multiple times)
|
39
|
+
def example(text)
|
40
|
+
Runner.instance.add_example text
|
41
|
+
end
|
42
|
+
|
38
43
|
# Define the action
|
39
44
|
def action(name, altname=nil, &block)
|
40
45
|
Runner.instance.add_action name, altname, &block
|
data/lib/runfile/runner.rb
CHANGED
@@ -16,15 +16,16 @@ module Runfile
|
|
16
16
|
|
17
17
|
# Initialize all variables to sensible defaults.
|
18
18
|
def initialize
|
19
|
-
@superspace = nil
|
20
|
-
@last_usage = nil
|
21
|
-
@last_help = nil
|
22
|
-
@namespace = nil
|
23
|
-
@actions
|
24
|
-
@options
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
19
|
+
@superspace = nil # used when filename != Runfile
|
20
|
+
@last_usage = nil # dsl: usage
|
21
|
+
@last_help = nil # dsl: help
|
22
|
+
@namespace = nil # dsl: command
|
23
|
+
@actions = {} # dsl: action
|
24
|
+
@options = {} # dsl: option
|
25
|
+
@examples = [] # dsl: example
|
26
|
+
@name = "Runfile" # dsl: name
|
27
|
+
@version = false # dsl: version
|
28
|
+
@summary = false # dsl: summary
|
28
29
|
end
|
29
30
|
|
30
31
|
# Return a singleton Runner instance.
|
@@ -72,6 +73,11 @@ module Runfile
|
|
72
73
|
@options[scope][flag] = text
|
73
74
|
end
|
74
75
|
|
76
|
+
# Add example command.
|
77
|
+
def add_example(command)
|
78
|
+
@examples << command
|
79
|
+
end
|
80
|
+
|
75
81
|
# Run the command. This is a wrapper around docopt. It will
|
76
82
|
# generate the docopt document on the fly, using all the
|
77
83
|
# information collected so far.
|
@@ -103,7 +109,7 @@ module Runfile
|
|
103
109
|
# This should always be called in a begin...rescue block and
|
104
110
|
# you should handle the Docopt::Exit exception.
|
105
111
|
def docopt_exec(argv)
|
106
|
-
helper = DocoptHelper.new(@superspace, @name, @version, @summary, @actions, @options)
|
112
|
+
helper = DocoptHelper.new(@superspace, @name, @version, @summary, @actions, @options, @examples)
|
107
113
|
args = helper.args argv
|
108
114
|
action = find_action argv
|
109
115
|
action or abort "Runfile error: Action not found"
|
data/lib/runfile/version.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.1
|
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-11-
|
11
|
+
date: 2015-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|