subcommand 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -0
  2. data/VERSION +1 -1
  3. data/lib/subcommand.rb +17 -9
  4. metadata +3 -3
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "sentinel.1879@gmail.com"
11
11
  gem.homepage = "http://github.com/rkumar/subcommand"
12
12
  gem.authors = ["Rahul Kumar"]
13
+ gem.rubyforge_project = "subcommand"
13
14
  #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
15
  gem.add_development_dependency "yard", ">= 0"
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.2
@@ -62,7 +62,6 @@ module Subcommands
62
62
  # Do repeatedly for each command
63
63
  # Yields the optionparser
64
64
  def command *names
65
- #puts "inside command with #{names} "
66
65
  name = names.shift
67
66
  @commands ||= {}
68
67
  @aliases ||= {}
@@ -95,8 +94,10 @@ module Subcommands
95
94
  # then parse subcommand options if valid subcommand
96
95
  # special case of "help command" so we print help of command - git style (3)
97
96
  # in all invalid cases print global help
97
+ # @return command name if relevant
98
98
  def opt_parse
99
99
  # if user has not defined global, we need to create it
100
+ @command_name = nil
100
101
  if !defined? @global
101
102
  global_options do |opts|
102
103
  opts.banner = "Usage: #{$0} [options] [subcommand [options]]"
@@ -135,37 +136,43 @@ module Subcommands
135
136
  @global.order!
136
137
  cmd = ARGV.shift
137
138
  if cmd
138
- #puts "Command: #{cmd} "
139
+ #puts "Command: #{cmd}, args:#{ARGV}, #{@commands.keys} "
139
140
  sc = @commands[cmd]
141
+ #puts "sc: #{sc}: #{@commands}"
142
+ #puts "sc: ="+@commands.include?(cmd)
140
143
  unless sc
141
144
  # see if an alias exists
142
- #puts "sc nil #{@aliases} "
143
145
  alas = @aliases[cmd]
144
- #puts "sc nil #{alas} "
145
146
  sc = @commands[alas] if alas
146
- #puts "sc nil #{sc} "
147
+ cmd = alas if alas
147
148
  end
148
149
  # if valid command parse the args
149
150
  if sc
151
+ @command_name = cmd
150
152
  sc.call.order!
151
153
  else
152
154
  # else if help <command> then print its help GIT style (3)
153
- if !ARGV.empty? and cmd == "help"
155
+ if !ARGV.empty? && cmd == "help"
154
156
  cmd = ARGV.shift
157
+ #puts " 110 help #{cmd}"
155
158
  sc = @commands[cmd]
156
159
  # if valid command print help, else print global help
157
160
  if sc
158
- #puts " 111 help foo/baz"
161
+ #puts " 111 help #{cmd}"
159
162
  puts sc.call
160
- else puts @global
163
+ else
164
+ puts "Invalid command: #{cmd}"
165
+ puts @global
161
166
  end
162
167
  else
163
168
  # invalid command
169
+ puts "Invalid command: #{cmd}"
164
170
  puts @global
165
171
  end
166
172
  exit 0
167
173
  end
168
174
  end
175
+ return @command_name
169
176
  end
170
177
  end
171
178
 
@@ -200,8 +207,9 @@ if __FILE__ == $PROGRAM_NAME
200
207
  end
201
208
 
202
209
  # do the parsing.
203
- opt_parse()
210
+ cmd = opt_parse()
204
211
 
212
+ puts "cmd: #{cmd}"
205
213
  puts "options ......"
206
214
  p options
207
215
  puts "ARGV:"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rahul Kumar
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: "0"
76
76
  requirements: []
77
77
 
78
- rubyforge_project:
78
+ rubyforge_project: subcommand
79
79
  rubygems_version: 1.3.6
80
80
  signing_key:
81
81
  specification_version: 3