subcommand 1.0.6 → 1.0.7

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2dd79eb88dc954b9ba2cae70a841e3fd51072f3caa93b92a5aac8649b595f4df
4
+ data.tar.gz: 7cb7704fe0cf5602db2f9bb1281dce48d95fadb46b018312dc36d79bb2a362a2
5
+ SHA512:
6
+ metadata.gz: 9aef53319c4814a566ded8ab4ccbfe21cb4e5cf544f76fde3c917cfbc465933c33731a677f046ab23113334ee1e8f4578c2b8d6e4ac8cd1b20fdac521accfebd
7
+ data.tar.gz: 0a43b94bbe4049db9ddc97df7cf833ee6018cfaa369c6cf1656ce81fa47d7849116d96503024a561bd0d0d24f353054bfb797360beb0274df424f037e9d849c5
@@ -1,9 +1,12 @@
1
+ = subcommand 1.0.6 2011-10-6
2
+ * added list_actions to facilitate dynamic custom completion using compctl etc
3
+
1
4
  = subcommand 1.0.4 2010-06-24 15:51
2
5
  * text for subcommands was being processed always before execution, so the
3
6
  point of lazy loading was lost. I've moved it away so it's only processed if
4
7
  actually printing help.
5
8
 
6
- Howeve, this means that if you are relying on OptionParser's implicit --help,
9
+ However, this means that if you are relying on OptionParser's implicit --help,
7
10
  that won't print subcommands. So i've added a method add_help_option which
8
11
  adds a correct help option, to print subcommands. This way, command help and
9
12
  command --help print identical output.
@@ -1,7 +1,7 @@
1
-
2
1
  = Subcommand
3
2
 
4
3
  A tiny wrapper over ruby's awesome OptionParser (standard) which gives easy facility of subcommands.
4
+
5
5
  It has a similar interface to git and prints subcommands summary as well.
6
6
 
7
7
  Options parsers are lazy-loaded thanks to a suggestion and sample code by Robert Klemme on ruby-forum.org.
@@ -38,7 +38,7 @@ Assuming a program "prog" with subcommands "del" and "add"
38
38
  ruby subcommand.rb baz --quiet "some text"
39
39
  ruby subcommand.rb --verbose foo --force file.zzz
40
40
 
41
- == STEPS
41
+ == STEPS
42
42
 
43
43
  1. define global_options (optional)
44
44
 
@@ -72,6 +72,25 @@ Assuming a program "prog" with subcommands "del" and "add"
72
72
 
73
73
  selected_command_name = opt_parse()
74
74
 
75
+ == Custom Completion
76
+ The command list_actions can be called from your application, so that the user
77
+ can have custom completion.
78
+
79
+ opts.on("--list-actions", "list actions for autocompletion ") do |v|
80
+ Subcommands::list_actions
81
+ exit 0
82
+ end
83
+
84
+ Now we can place something like this in a configuration file. Here's what i placed
85
+ in .zshrc for bugzyrb.
86
+
87
+ _bugzyrb() {
88
+ reply=(`bugzyrb --list-actions`)
89
+ }
90
+ compctl -K _bugzyrb bugzyrb
91
+
92
+ Now, on the command line when I type "bugzyrb <TAB>" the actions are prompted in a menu.
93
+
75
94
  == Sample Output
76
95
 
77
96
  $ ruby subcommand.rb help
@@ -86,7 +105,7 @@ Assuming a program "prog" with subcommands "del" and "add"
86
105
  foo : desc for foo
87
106
  baz : desc for baz
88
107
 
89
- Aliases:
108
+ Aliases:
90
109
  goo - foo
91
110
 
92
111
  See 'subcommand.rb help COMMAND' for more information on a specific command.
@@ -117,16 +136,11 @@ You should have no errors. The test cases are in the **tests** folder.
117
136
 
118
137
  http://subcommand.rubyforge.org/doc/
119
138
 
120
- == Note on Patches/Pull Requests
121
-
122
- * Fork the project.
123
- * Make your feature addition or bug fix.
124
- * Add tests for it. This is important so I don't break it in a
125
- future version unintentionally.
126
- * Commit, do not mess with rakefile, version, or history.
127
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
128
- * Send me a pull request. Bonus points for topic branches.
129
-
130
139
  == Copyright
131
140
 
132
- Copyright (c) 2010 Rahul Kumar. See LICENSE for details.
141
+ Copyright (c) 2010-2019 Rahul Kumar. See LICENSE for details.
142
+
143
+ == Others
144
+
145
+ This simple gem is still working fine. No need for a new release.
146
+ Working with ruby 1.9 through 2.6.
data/Rakefile CHANGED
@@ -1,54 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require "bundler/gem_tasks"
3
2
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "subcommand"
8
- gem.summary = %Q{A tiny wrapper over OptionParser giving simple, elegant subcommand facility}
9
- gem.description = %Q{Subcommand and alias facility (wrapping OptionParser) for command line programs with elegant help printing}
10
- gem.email = "sentinel.1879@gmail.com"
11
- gem.homepage = "http://github.com/rkumar/subcommand"
12
- gem.authors = ["Rahul Kumar"]
13
- gem.rubyforge_project = "subcommand"
14
- #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
- gem.add_development_dependency "yard", ">= 0"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
22
-
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/test_*.rb'
27
- test.verbose = true
28
- end
29
-
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
41
- end
42
-
43
- task :test => :check_dependencies
44
-
45
- task :default => :test
46
-
47
- begin
48
- require 'yard'
49
- YARD::Rake::YardocTask.new
50
- rescue LoadError
51
- task :yardoc do
52
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
53
- end
54
- end
@@ -5,9 +5,9 @@
5
5
  # as well as summarizes subcommands in global help.
6
6
  #
7
7
  # Thanks to Robert Klemme for his idea on lazy loading the subcommand option parsers.
8
- #
8
+ #
9
9
  # @author Rahul Kumar, Jun 2010
10
- # @date 2010-06-20 22:33
10
+ # @date 2010-06-20 22:33
11
11
  #
12
12
  # @examples
13
13
  # if a program has subcommands foo and baz
@@ -19,7 +19,7 @@
19
19
  # ruby subcommand.rb baz --quiet "some text"
20
20
  # ruby subcommand.rb --verbose foo --force file.zzz
21
21
  #
22
- # == STEPS
22
+ # == STEPS
23
23
  # 1. define global_options (optional)
24
24
  #
25
25
  # global_options do |opts|
@@ -66,7 +66,7 @@ module Subcommands
66
66
  @commands ||= {}
67
67
  @aliases ||= {}
68
68
  if names.length > 0
69
- names.each do |n|
69
+ names.each do |n|
70
70
  #puts "aliases #{n} => #{name} "
71
71
  @aliases[n.to_s] = name.to_s
72
72
  end
@@ -91,6 +91,7 @@ module Subcommands
91
91
  end
92
92
  end
93
93
 
94
+
94
95
  # Added so applications can print out a bare listing of top level commands
95
96
  # for dynamic custom completion.
96
97
  def list_actions
@@ -100,7 +101,7 @@ module Subcommands
100
101
 
101
102
  def print_actions
102
103
  cmdtext = "Commands are:"
103
- @commands.each_pair do |c, opt|
104
+ @commands.each_pair do |c, opt|
104
105
  #puts "inside opt.call loop"
105
106
  desc = opt.call.description
106
107
  cmdtext << "\n #{c} : #{desc}"
@@ -108,7 +109,7 @@ module Subcommands
108
109
 
109
110
  # print aliases
110
111
  unless @aliases.empty?
111
- cmdtext << "\n\nAliases: \n"
112
+ cmdtext << "\n\nAliases: \n"
112
113
  @aliases.each_pair { |name, val| cmdtext << " #{name} - #{val}\n" }
113
114
  end
114
115
 
@@ -134,12 +135,17 @@ module Subcommands
134
135
  def add_help_option
135
136
  global_options do |opts|
136
137
  opts.on("-h", "--help", "Print this help") do |v|
137
- add_subcommand_help
138
- puts @global
138
+ print_help
139
139
  exit
140
140
  end
141
141
  end
142
142
  end
143
+
144
+ def print_help
145
+ add_subcommand_help
146
+ puts @global
147
+ end
148
+
143
149
  # first parse global optinos
144
150
  # then parse subcommand options if valid subcommand
145
151
  # special case of "help command" so we print help of command - git style (3)
@@ -154,8 +160,7 @@ module Subcommands
154
160
  opts.separator ""
155
161
  opts.separator "Global options are:"
156
162
  opts.on("-h", "--help", "Print this help") do |v|
157
- add_subcommand_help
158
- puts @global
163
+ print_help
159
164
  exit
160
165
  end
161
166
  opts.separator ""
@@ -167,7 +172,7 @@ module Subcommands
167
172
  cmd = ARGV.shift
168
173
  if cmd
169
174
  #$stderr.puts "Command: #{cmd}, args:#{ARGV}, #{@commands.keys} "
170
- sc = @commands[cmd]
175
+ sc = @commands[cmd]
171
176
  #puts "sc: #{sc}: #{@commands}"
172
177
  unless sc
173
178
  # see if an alias exists
@@ -190,20 +195,22 @@ module Subcommands
190
195
  if sc
191
196
  #puts " 111 help #{cmd}"
192
197
  puts sc.call
193
- else
198
+ else
194
199
  # no help for this command XXX check for alias
195
200
  puts "Invalid command: #{cmd}."
196
- add_subcommand_help
197
- puts @global
201
+ print_help
198
202
  end
199
203
  else
200
- # invalid command
204
+ # invalid command
201
205
  puts "Invalid command: #{cmd}" unless cmd == "help"
202
- add_subcommand_help
203
- puts @global
206
+ print_help
204
207
  end
205
208
  exit 0
206
209
  end
210
+ else
211
+ puts "Empty command!"
212
+ print_help
213
+ exit 1
207
214
  end
208
215
  return @command_name
209
216
  end
@@ -1,17 +1,14 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
- s.name = %q{subcommand}
8
- s.version = "1.0.6"
4
+ s.name = 'subcommand'
5
+ s.version = '1.0.7'
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = [%q{Rahul Kumar}]
12
9
  s.date = %q{2011-10-06}
13
10
  s.description = %q{Subcommand and alias facility (wrapping OptionParser) for command line programs with elegant help printing}
14
- s.email = %q{sentinel.1879@gmail.com}
11
+ s.email = %q{oneness.univ@gmail.com}
15
12
  s.extra_rdoc_files = [
16
13
  "LICENSE",
17
14
  "README.rdoc",
@@ -47,7 +44,6 @@ Gem::Specification.new do |s|
47
44
  s.homepage = %q{http://github.com/rkumar/subcommand}
48
45
  s.require_paths = [%q{lib}]
49
46
  s.rubyforge_project = %q{subcommand}
50
- s.rubygems_version = %q{1.8.8}
51
47
  s.summary = %q{A tiny wrapper over OptionParser giving simple, elegant subcommand facility}
52
48
 
53
49
  if s.respond_to? :specification_version then
@@ -62,4 +58,3 @@ Gem::Specification.new do |s|
62
58
  s.add_dependency(%q<yard>, [">= 0"])
63
59
  end
64
60
  end
65
-
metadata CHANGED
@@ -1,45 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: subcommand
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Rahul Kumar
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-10-06 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2011-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: yard
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
21
17
  - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
24
20
  type: :development
25
- version_requirements: *id001
26
- description: Subcommand and alias facility (wrapping OptionParser) for command line programs with elegant help printing
27
- email: sentinel.1879@gmail.com
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Subcommand and alias facility (wrapping OptionParser) for command line
28
+ programs with elegant help printing
29
+ email: oneness.univ@gmail.com
28
30
  executables: []
29
-
30
31
  extensions: []
31
-
32
- extra_rdoc_files:
32
+ extra_rdoc_files:
33
33
  - LICENSE
34
34
  - README.rdoc
35
35
  - TODO
36
- files:
37
- - .document
36
+ files:
37
+ - ".document"
38
38
  - CHANGELOG.rdoc
39
39
  - LICENSE
40
40
  - Makefile
41
41
  - README.rdoc
42
42
  - Rakefile
43
+ - TODO
43
44
  - VERSION
44
45
  - lib/subcommand.rb
45
46
  - subcommand.gemspec
@@ -59,33 +60,26 @@ files:
59
60
  - tests/test-lib.sh
60
61
  - tests/test.rb
61
62
  - tests/test1.rb
62
- - TODO
63
63
  homepage: http://github.com/rkumar/subcommand
64
64
  licenses: []
65
-
65
+ metadata: {}
66
66
  post_install_message:
67
67
  rdoc_options: []
68
-
69
- require_paths:
68
+ require_paths:
70
69
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
74
72
  - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
77
- required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
- requirements:
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
80
77
  - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
83
80
  requirements: []
84
-
85
- rubyforge_project: subcommand
86
- rubygems_version: 1.8.8
81
+ rubygems_version: 3.0.3
87
82
  signing_key:
88
83
  specification_version: 3
89
84
  summary: A tiny wrapper over OptionParser giving simple, elegant subcommand facility
90
85
  test_files: []
91
-