runfile 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0980ca227f78853f3dcf034253d57a0ac61f5cc0
4
- data.tar.gz: c5548ead96c34f0dbcfa59a48d64153463b5b75e
3
+ metadata.gz: 7b0ef66864e2ac38cb60c3c8f78b0641143ebe67
4
+ data.tar.gz: 73af9361c6dee752c2d819b4215326e890782cb5
5
5
  SHA512:
6
- metadata.gz: 1a960d00b7663752bb7e6f7264323c2d5e654fac533f391dc54c1dcced5e1aa9e171e7cd55f199855fe908e64660b2680d5aa63c646aeffd2c252ae2c119d223
7
- data.tar.gz: 367511ebf703bb821a5acec2742e8371d0459e0f7adbb4998871cf40044792aa5646be49b06993ab82588aa060c3d42c7ebcde59e97d57a4bec56198a09ca5fe
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
@@ -16,15 +16,16 @@ module Runfile
16
16
 
17
17
  # Initialize all variables to sensible defaults.
18
18
  def initialize
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
- @name = "Runfile" # dsl: name
26
- @version = false # dsl: version
27
- @summary = false # dsl: summary
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"
@@ -1,3 +1,3 @@
1
1
  module Runfile
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  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.5.0
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-01 00:00:00.000000000 Z
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole