subcommander 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.markdown +43 -7
  2. data/lib/subcommander.rb +1 -1
  3. metadata +4 -4
@@ -1,4 +1,4 @@
1
- Subcommander is a wrapper around Ruby's OptionParser class that allows you to have sub-commands like we see in Git and other tools. To get help for your tool, just type in the tool name with no sub-command (or the word "help" as a sub-command). To get help for a sub-command type:
1
+ Subcommander is a wrapper around Ruby's OptionParser class that allows you to have sub-commands like we see in Git and other tools. Subcommands can be nested so your subcommands can have subcommands. To get help for your tool, just type in the tool name with no sub-command (or the word "help" as a sub-command). To get help for a sub-command type:
2
2
 
3
3
  your-tool help sub-command
4
4
 
@@ -6,7 +6,7 @@ More description coming... this is basically a placeholder for now.
6
6
 
7
7
  ### Simple Example:
8
8
 
9
- require 'subcommander'
9
+ %w[rubygems subcommander].each { |m| require m }
10
10
  include Subcommander
11
11
 
12
12
  subcommander.version = '1.0.0'
@@ -26,16 +26,50 @@ More description coming... this is basically a placeholder for now.
26
26
 
27
27
  subcommander.go!
28
28
 
29
+ ### Nested Subcommands Example:
30
+
31
+ %w[rubygems subcommander].each { |m| require m }
32
+ include Subcommander
33
+
34
+ subcommander.version = '1.0.0'
35
+ subcommander.desc = "ComplexTool is ephemeral and only here to demonstrate Subcommander."
36
+
37
+ subcommand :run, "Commands for running the complex tool" do |run|
38
+ run.subcommand 'on-foot', "Run down the street" do |sc|
39
+ sc.usage = "complextool run on-foot [-f | -s]"
40
+ sc.opt :fast, '-f', '--fast', "Run fast!"
41
+ sc.opt :slow, '-s', '--slow', "Run slow."
42
+ sc.exec {
43
+ speed = "at a normal pace"
44
+ if sc[:fast]
45
+ speed = 'fast'
46
+ elsif sc[:slow]
47
+ speed = 'slow'
48
+ end
49
+ puts "We're running #{speed}"
50
+ }
51
+ end
52
+ run.subcommand 'an-app', "Run an app" do |sc|
53
+ sc.arity = 1
54
+ sc.usage = "complextool run an-app NAME"
55
+ sc.exec {
56
+ app = sc[:remaining_args][0]
57
+ puts "Running #{app}"
58
+ }
59
+ end
60
+ end
61
+
62
+ subcommander.go!
63
+
29
64
  ---------------------------
30
65
 
31
66
  # subcommander #
32
67
 
33
68
  Properties you can set:
34
69
 
35
- __version__ - The version of the tool you're making. It's printed at the bottom of help.
36
-
37
70
  __desc__ - A description of the tool you're using. It's printed at the beginning of help.
38
71
 
72
+ __version__ - The version of the tool you're making. It's printed at the bottom of help.
39
73
 
40
74
  ---------------------------
41
75
  # subcommand #
@@ -44,11 +78,13 @@ Properties you can set:
44
78
 
45
79
  __arity__ - This says how many arguemnts are expected to be passed to this sub-command, excluding options and their arguemnts.
46
80
 
47
- __help__ - Help that shows up when the user asks for help about the sub-command
81
+ __exec__ - The implementation for your sub-command should be in a block that's passed to this method.
48
82
 
49
- __usage__ - The typical usage pattern like "simple-tool [options] args"
83
+ __help__ - Help that shows up when the user asks for help about the sub-command
50
84
 
51
85
  __opt__ - These are exactly the same as OptionParser opt.on() argument lists except the first argument is a token. When the option is invoked, it will put any option arguemnts that were passed into the subcommand keyed by that token. So subcommand[:yoursymbol] is where you'll find it when you're looking for it in your exec block.
52
86
 
53
- __exec__ - The implementation for your sub-command should be in a block that's passed to this method.
87
+ __subcommand__ - Allows your subcommand to have it's own subcommands.
88
+
89
+ __usage__ - The typical usage pattern like "simple-tool [options] args"
54
90
 
@@ -141,7 +141,7 @@ module Subcommander
141
141
  def subcommand name, desc, &block
142
142
  unless @sub_cmdr
143
143
  @sub_cmdr = Subcommander.new(@args.clone())
144
- @sub_cmdr.desc = lambda { @help }
144
+ @sub_cmdr.desc = lambda { @help ? @help : @desc }
145
145
  end
146
146
  @sub_cmdr.subcommand(name, desc, &block)
147
147
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subcommander
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Santos
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-17 00:00:00 -07:00
18
+ date: 2011-05-18 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21