clive 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/clive.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{clive}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Joshua Hawxwell"]
12
+ s.date = %q{2010-08-14}
13
+ s.description = %q{Clive is a DSL for creating a command line interface. It is for people who, like me, love OptionParser's syntax and love GLI's commands.}
14
+ s.email = %q{m@hawx.me}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "clive.gemspec",
27
+ "lib/clive.rb",
28
+ "lib/clive/commands.rb",
29
+ "lib/clive/ext.rb",
30
+ "lib/clive/flags.rb",
31
+ "lib/clive/switches.rb",
32
+ "lib/clive/tokens.rb",
33
+ "test/bin_test",
34
+ "test/helper.rb",
35
+ "test/test_clive.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/hawx/clive}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{Imagine if optparse and gli had a son called clive.}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_clive.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ s.add_development_dependency(%q<yard>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_dependency(%q<yard>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_dependency(%q<yard>, [">= 0"])
61
+ end
62
+ end
63
+
@@ -9,6 +9,7 @@ class Clive
9
9
  attr_accessor :switches, :flags, :commands
10
10
  attr_accessor :name, :desc, :block, :argv
11
11
  attr_accessor :base
12
+ attr_accessor :banner
12
13
 
13
14
  # Create a new Command instance
14
15
  #
@@ -44,6 +45,12 @@ class Clive
44
45
  end
45
46
  @block = block
46
47
  end
48
+
49
+ @banner = "Usage: #{File.basename($0, '.*')} "
50
+ @banner << (@base ? "[commands]" : @name)
51
+ @banner << " [options]"
52
+
53
+ self.build_help
47
54
  end
48
55
 
49
56
  # Run the block that was passed to find switches, flags, etc.
@@ -62,7 +69,7 @@ class Clive
62
69
  # @param [Array] argv the command line input, usually just ARGV
63
70
  # @return [Array] any arguments that were present in the input but not used
64
71
  #
65
- def run(argv)
72
+ def run(argv=[])
66
73
  tokens = argv
67
74
  tokens = tokenize(argv) if @base
68
75
 
@@ -220,5 +227,55 @@ class Clive
220
227
  @flags << Flag.new(short, long, desc, &block)
221
228
  end
222
229
 
230
+ #### HELP STUFF ####
231
+
232
+ # This actually creates a switch with "-h" and "--help" that control
233
+ # the help on this command. If this is the base class it will also
234
+ # creates a "help [command]" command.
235
+ def build_help
236
+ @switches << Switch.new("h", "help", "Display help") {puts self.help}
237
+ end
238
+
239
+ # Set the banner
240
+ def banner(val)
241
+ @banner = val
242
+ end
243
+
244
+ def summary(width=30, prepend=5)
245
+ a = @name
246
+ b = @desc
247
+ s, p = '', ''
248
+ (0..width-a.length).each {s << ' '}
249
+ (0..prepend).each {p << ' '}
250
+ "#{p}#{a}#{s}#{b}"
251
+ end
252
+
253
+ # Generate the summary for help, show all flags and switches, but do not
254
+ # show the flags and switches within each command. Should also prepend the
255
+ # banner.
256
+ def help(width=30, prepend=5)
257
+ summary = "#{@banner}\n"
258
+
259
+ if @switches.length > 0 || @flags.length > 0
260
+ summary << "\n Options:\n"
261
+ @switches.each do |i|
262
+ summary << i.summary(width, prepend) << "\n"
263
+ end
264
+ @flags.each do |i|
265
+ summary << i.summary(width, prepend) << "\n"
266
+ end
267
+ end
268
+
269
+ if @commands.length > 0
270
+ summary << "\nCommands:\n"
271
+ @commands.each do |i|
272
+ summary << i.summary(width, prepend) << "\n"
273
+ end
274
+ end
275
+
276
+ summary
277
+ end
278
+
279
+
223
280
  end
224
281
  end
@@ -19,6 +19,19 @@ class Clive
19
19
  @block.call
20
20
  end
21
21
 
22
+ # @return [String] summary for help
23
+ def summary(width=30, prepend=5)
24
+ a = ""
25
+ a << "-#{@short}" if @short
26
+ a << ", " if @short && @long
27
+ a << "--#{@long}" if @long
28
+ b = @desc
29
+ s, p = '', ''
30
+ (0..width-a.length).each {s << ' '}
31
+ (0..prepend).each {p << ' '}
32
+ "#{p}#{a}#{s}#{b}"
33
+ end
34
+
22
35
  end
23
36
 
24
37
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clive
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hawxwell
@@ -62,6 +62,7 @@ files:
62
62
  - README.md
63
63
  - Rakefile
64
64
  - VERSION
65
+ - clive.gemspec
65
66
  - lib/clive.rb
66
67
  - lib/clive/commands.rb
67
68
  - lib/clive/ext.rb