choosy 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +7 -1
- data/Rakefile +15 -43
- data/lib/VERSION.yml +1 -1
- data/lib/choosy/printing/manpage.rb +2 -1
- data/lib/choosy/printing/manpage_printer.rb +2 -2
- data/lib/choosy/version.rb +22 -0
- data/lib/choosy/versiontask.rb +30 -0
- data/spec/choosy/printing/manpage_spec.rb +2 -1
- metadata +112 -134
- data/examples/bar.rb +0 -46
- data/examples/foo.rb +0 -200
- data/examples/superfoo.rb +0 -137
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -1,32 +1,23 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
begin
|
2
|
+
require 'choosy/versiontask'
|
3
|
+
rescue LoadError => e
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
|
5
|
+
require 'choosy/versiontask'
|
6
|
+
end
|
3
7
|
|
4
8
|
require 'rubygems'
|
5
9
|
require 'rake'
|
6
|
-
#require 'rake/rdoctask'
|
7
10
|
require 'rspec/core/rake_task'
|
8
|
-
require '
|
11
|
+
require 'bundler'
|
12
|
+
Bundler::GemHelper.install_tasks
|
9
13
|
|
10
14
|
PACKAGE_NAME = "choosy"
|
11
|
-
PACKAGE_VERSION = Choosy::Version.new(File.join(File.dirname(__FILE__), 'lib', 'VERSION.yml'))
|
12
15
|
|
13
16
|
desc "Default task"
|
14
17
|
task :default => [ :spec ]
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
task :tiny do
|
19
|
-
PACKAGE_VERSION.version!(:tiny)
|
20
|
-
end
|
21
|
-
desc "Minor bump"
|
22
|
-
task :minor do
|
23
|
-
PACKAGE_VERSION.version!(:minor)
|
24
|
-
end
|
25
|
-
desc "Major bump"
|
26
|
-
task :major do
|
27
|
-
PACKAGE_VERSION.version!(:major)
|
28
|
-
end
|
29
|
-
end
|
19
|
+
desc "Run the RSpec tests"
|
20
|
+
RSpec::Core::RakeTask.new :spec
|
30
21
|
|
31
22
|
desc "Build documentation"
|
32
23
|
task :doc => [ :rdoc ] do
|
@@ -58,27 +49,6 @@ end
|
|
58
49
|
desc "Create RDocs: TODO"
|
59
50
|
task :rdoc
|
60
51
|
|
61
|
-
desc "Run the RSpec tests"
|
62
|
-
RSpec::Core::RakeTask.new :spec
|
63
|
-
|
64
|
-
begin
|
65
|
-
require 'jeweler'
|
66
|
-
Jeweler::Tasks.new do |gem|
|
67
|
-
gem.name = PACKAGE_NAME
|
68
|
-
gem.version = PACKAGE_VERSION.to_s
|
69
|
-
gem.summary = 'Yet another option parsing library.'
|
70
|
-
gem.description = 'This is a DSL for creating more complicated command line tools.'
|
71
|
-
gem.email = ['madeonamac@gmail.com']
|
72
|
-
gem.authors = ['Gabe McArthur']
|
73
|
-
gem.homepage = 'http://github.com/gabemc/choosy'
|
74
|
-
gem.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
|
75
|
-
|
76
|
-
gem.add_development_dependency 'rspec', '~> 2.5'
|
77
|
-
end
|
78
|
-
rescue LoadError
|
79
|
-
puts "Jeweler or dependencies are not available. Install it with: gem install jeweler"
|
80
|
-
end
|
81
|
-
|
82
52
|
desc "Cleans the generated files."
|
83
53
|
task :clean do
|
84
54
|
rm Dir.glob('*.gemspec')
|
@@ -87,9 +57,11 @@ task :clean do
|
|
87
57
|
end
|
88
58
|
|
89
59
|
desc "Deploys the gem to rubygems.org"
|
90
|
-
task :gem => [:doc, :
|
91
|
-
|
92
|
-
|
60
|
+
task :gem => [:doc, :version] do
|
61
|
+
sh "gem build #{PACKAGE_NAME}.gemspec"
|
62
|
+
sh "gem push #{PACKAGE_NAME}-#{$version}.gem"
|
63
|
+
sh "git tag -m 'Tagging release #{$version}' v#{$version}"
|
64
|
+
sh "git push origin :refs/tags/#{$version}"
|
93
65
|
end
|
94
66
|
|
95
67
|
desc "Does the full release cycle."
|
data/lib/VERSION.yml
CHANGED
@@ -146,7 +146,7 @@ module Choosy::Printing
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def comment(line)
|
149
|
-
append('
|
149
|
+
append('.\\" ' << line)
|
150
150
|
end
|
151
151
|
|
152
152
|
def line_break
|
@@ -173,6 +173,7 @@ module Choosy::Printing
|
|
173
173
|
|
174
174
|
def to_s(io=nil)
|
175
175
|
io ||= ""
|
176
|
+
io << "'\\\" t\n"
|
176
177
|
io << frame_outline << NEWLINE
|
177
178
|
io << PREFACE
|
178
179
|
@buffer.each do |line|
|
@@ -22,9 +22,9 @@ module Choosy::Printing
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def print!(command)
|
25
|
-
if pager?
|
25
|
+
if command_exists?('groff') && pager?
|
26
26
|
fix_termcap
|
27
|
-
page format!(command), 'groff -Tutf8 -mandoc'
|
27
|
+
page format!(command), 'groff -t -e -W all -Tutf8 -mandoc'
|
28
28
|
else
|
29
29
|
# Fall back to a help printer if there is no pager
|
30
30
|
help = HelpPrinter.new(formatting_options)
|
data/lib/choosy/version.rb
CHANGED
@@ -60,6 +60,28 @@ module Choosy
|
|
60
60
|
"#{major}.#{minor}.#{tiny}"
|
61
61
|
end
|
62
62
|
|
63
|
+
def self.load(options)
|
64
|
+
basepath = if options[:file] && options[:relpath]
|
65
|
+
File.join(File.dirname(options[:file]), options[:relpath])
|
66
|
+
elsif options[:dir]
|
67
|
+
if options[:relpath]
|
68
|
+
File.join(options[:dir], options[:relpath])
|
69
|
+
else
|
70
|
+
options[:dir]
|
71
|
+
end
|
72
|
+
else
|
73
|
+
Choosy::ConfigurationError.new("No file given.")
|
74
|
+
end
|
75
|
+
|
76
|
+
[File.join(basepath, 'VERSION.yml'), File.join(basepath, 'version.yml')].each do |path|
|
77
|
+
if File.exist?(path)
|
78
|
+
return Version.new(path)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
raise Choosy::ConfigurationError.new("No version file given from: #{basepath}")
|
83
|
+
end
|
84
|
+
|
63
85
|
private
|
64
86
|
VERSION = 'version'
|
65
87
|
TINY = 'tiny'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
# This is a library task that others can use to expose functionality in their rake files
|
3
|
+
# It defines the '$version' global variable to let users pull this information out
|
4
|
+
# into their own scripts.
|
5
|
+
|
6
|
+
require 'choosy/version'
|
7
|
+
|
8
|
+
desc "Shows the current version number."
|
9
|
+
task :version => ['version:load'] do
|
10
|
+
puts "Current version: #{$version.to_s}"
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :version do
|
14
|
+
task :load do
|
15
|
+
puts Dir.pwd
|
16
|
+
if ENV['VERSION_FILE']
|
17
|
+
$version = Choosy::Version.new(ENV['VERSION_FILE'])
|
18
|
+
else
|
19
|
+
$version = Choosy::Version.load(:dir => Dir.pwd, :relpath => 'lib')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
[:tiny, :minor, :major].each do |type|
|
24
|
+
desc "Bumps the #{type} revision number."
|
25
|
+
task type => :load do
|
26
|
+
$version.version!(type)
|
27
|
+
puts "New version: #{$version.to_s}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -147,7 +147,7 @@ module Choosy::Printing
|
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should allow for comments" do
|
150
|
-
@man.comment("here").should eql('
|
150
|
+
@man.comment("here").should eql('.\\" here')
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should allow for line breaks" do
|
@@ -188,6 +188,7 @@ module Choosy::Printing
|
|
188
188
|
@man.paragraph('this is a line of text')
|
189
189
|
|
190
190
|
@man.to_s.should eql(<<EOF
|
191
|
+
'\\" t
|
191
192
|
.TH "blah" "1" "today" " " " "
|
192
193
|
.ie \\n(.g .ds Aq \\(aq
|
193
194
|
.el .ds Aq '
|
metadata
CHANGED
@@ -1,194 +1,172 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: choosy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Gabe McArthur
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
16
|
+
|
17
|
+
date: 2011-03-25 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
requirement: &81909430 !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
type: :development
|
24
22
|
prerelease: false
|
25
|
-
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: autotest
|
28
|
-
requirement: &81909190 !ruby/object:Gem::Requirement
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
29
24
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 5
|
31
|
+
version: "2.5"
|
34
32
|
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: autotest
|
35
36
|
prerelease: false
|
36
|
-
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: autotest-notification
|
39
|
-
requirement: &81908950 !ruby/object:Gem::Requirement
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
38
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
45
|
type: :development
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: autotest-notification
|
46
49
|
prerelease: false
|
47
|
-
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rspec
|
50
|
-
requirement: &81908710 !ruby/object:Gem::Requirement
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
56
58
|
type: :development
|
57
|
-
|
58
|
-
version_requirements: *81908710
|
59
|
+
version_requirements: *id003
|
59
60
|
description: This is a DSL for creating more complicated command line tools.
|
60
|
-
email:
|
61
|
+
email:
|
61
62
|
- madeonamac@gmail.com
|
62
63
|
executables: []
|
64
|
+
|
63
65
|
extensions: []
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
files:
|
68
|
-
-
|
66
|
+
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
69
|
+
files:
|
70
|
+
- TODO.md
|
69
71
|
- Gemfile
|
72
|
+
- README.markdown
|
70
73
|
- Gemfile.lock
|
74
|
+
- CHANGELOG.md
|
71
75
|
- LICENSE
|
72
|
-
- README.markdown
|
73
76
|
- Rakefile
|
74
|
-
- TODO.md
|
75
|
-
- lib/VERSION.yml
|
76
77
|
- lib/choosy.rb
|
78
|
+
- lib/VERSION.yml
|
79
|
+
- lib/choosy/errors.rb
|
80
|
+
- lib/choosy/printing.rb
|
81
|
+
- lib/choosy/converter.rb
|
82
|
+
- lib/choosy/parse_result.rb
|
83
|
+
- lib/choosy/verifier.rb
|
77
84
|
- lib/choosy/argument.rb
|
78
|
-
- lib/choosy/
|
85
|
+
- lib/choosy/version.rb
|
86
|
+
- lib/choosy/option.rb
|
79
87
|
- lib/choosy/command.rb
|
80
|
-
- lib/choosy/
|
88
|
+
- lib/choosy/super_command.rb
|
81
89
|
- lib/choosy/dsl/argument_builder.rb
|
90
|
+
- lib/choosy/dsl/super_command_builder.rb
|
82
91
|
- lib/choosy/dsl/base_builder.rb
|
83
|
-
- lib/choosy/dsl/base_command_builder.rb
|
84
92
|
- lib/choosy/dsl/command_builder.rb
|
85
93
|
- lib/choosy/dsl/option_builder.rb
|
86
|
-
- lib/choosy/dsl/
|
87
|
-
- lib/choosy/
|
88
|
-
- lib/choosy/option.rb
|
89
|
-
- lib/choosy/parse_result.rb
|
94
|
+
- lib/choosy/dsl/base_command_builder.rb
|
95
|
+
- lib/choosy/versiontask.rb
|
90
96
|
- lib/choosy/parser.rb
|
91
|
-
- lib/choosy/
|
97
|
+
- lib/choosy/base_command.rb
|
98
|
+
- lib/choosy/printing/manpage_printer.rb
|
92
99
|
- lib/choosy/printing/base_printer.rb
|
93
|
-
- lib/choosy/printing/color.rb
|
94
|
-
- lib/choosy/printing/erb_printer.rb
|
95
100
|
- lib/choosy/printing/formatting_element.rb
|
96
|
-
- lib/choosy/printing/help_printer.rb
|
97
101
|
- lib/choosy/printing/manpage.rb
|
98
|
-
- lib/choosy/printing/manpage_printer.rb
|
99
102
|
- lib/choosy/printing/terminal.rb
|
100
|
-
- lib/choosy/
|
103
|
+
- lib/choosy/printing/color.rb
|
104
|
+
- lib/choosy/printing/erb_printer.rb
|
105
|
+
- lib/choosy/printing/help_printer.rb
|
101
106
|
- lib/choosy/super_parser.rb
|
102
|
-
-
|
103
|
-
-
|
107
|
+
- spec/integration/command-A_spec.rb
|
108
|
+
- spec/integration/supercommand-C_spec.rb
|
109
|
+
- spec/integration/command-B_spec.rb
|
110
|
+
- spec/integration/supercommand-B_spec.rb
|
111
|
+
- spec/integration/supercommand-A_spec.rb
|
112
|
+
- spec/integration/command-C_spec.rb
|
113
|
+
- spec/choosy/converter_spec.rb
|
114
|
+
- spec/choosy/option_spec.rb
|
115
|
+
- spec/choosy/version_spec.rb
|
104
116
|
- spec/choosy/argument_spec.rb
|
105
117
|
- spec/choosy/base_command_spec.rb
|
118
|
+
- spec/choosy/version.yml
|
106
119
|
- spec/choosy/command_spec.rb
|
107
|
-
- spec/choosy/
|
108
|
-
- spec/choosy/dsl/
|
120
|
+
- spec/choosy/dsl/super_command_builder_spec.rb
|
121
|
+
- spec/choosy/dsl/option_builder_spec.rb
|
109
122
|
- spec/choosy/dsl/base_builder_spec.rb
|
110
|
-
- spec/choosy/dsl/
|
123
|
+
- spec/choosy/dsl/argument_builder_spec.rb
|
111
124
|
- spec/choosy/dsl/commmand_builder_spec.rb
|
112
|
-
- spec/choosy/dsl/
|
113
|
-
- spec/choosy/dsl/super_command_builder_spec.rb
|
114
|
-
- spec/choosy/option_spec.rb
|
115
|
-
- spec/choosy/parser_spec.rb
|
116
|
-
- spec/choosy/printing/base_printer_spec.rb
|
117
|
-
- spec/choosy/printing/color_spec.rb
|
118
|
-
- spec/choosy/printing/help_printer_spec.rb
|
119
|
-
- spec/choosy/printing/manpage_printer_spec.rb
|
120
|
-
- spec/choosy/printing/manpage_spec.rb
|
121
|
-
- spec/choosy/printing/terminal_spec.rb
|
125
|
+
- spec/choosy/dsl/base_command_builder_spec.rb
|
122
126
|
- spec/choosy/super_command_spec.rb
|
123
127
|
- spec/choosy/super_parser_spec.rb
|
124
128
|
- spec/choosy/verifier_spec.rb
|
125
|
-
- spec/choosy/
|
126
|
-
- spec/choosy/
|
127
|
-
- spec/
|
128
|
-
- spec/
|
129
|
-
- spec/
|
130
|
-
- spec/
|
131
|
-
- spec/
|
132
|
-
- spec/integration/supercommand-C_spec.rb
|
129
|
+
- spec/choosy/printing/help_printer_spec.rb
|
130
|
+
- spec/choosy/printing/terminal_spec.rb
|
131
|
+
- spec/choosy/printing/base_printer_spec.rb
|
132
|
+
- spec/choosy/printing/manpage_printer_spec.rb
|
133
|
+
- spec/choosy/printing/color_spec.rb
|
134
|
+
- spec/choosy/printing/manpage_spec.rb
|
135
|
+
- spec/choosy/parser_spec.rb
|
133
136
|
- spec/spec_helpers.rb
|
134
|
-
- examples/bar.rb
|
135
|
-
- examples/foo.rb
|
136
|
-
- examples/superfoo.rb
|
137
137
|
has_rdoc: true
|
138
138
|
homepage: http://github.com/gabemc/choosy
|
139
139
|
licenses: []
|
140
|
+
|
140
141
|
post_install_message:
|
141
142
|
rdoc_options: []
|
142
|
-
|
143
|
+
|
144
|
+
require_paths:
|
143
145
|
- lib
|
144
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
147
|
none: false
|
146
|
-
requirements:
|
147
|
-
- -
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
|
150
|
-
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
155
|
none: false
|
152
|
-
requirements:
|
153
|
-
- -
|
154
|
-
- !ruby/object:Gem::Version
|
155
|
-
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
segments:
|
160
|
+
- 1
|
161
|
+
- 3
|
162
|
+
- 6
|
163
|
+
version: 1.3.6
|
156
164
|
requirements: []
|
165
|
+
|
157
166
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.
|
167
|
+
rubygems_version: 1.3.7
|
159
168
|
signing_key:
|
160
169
|
specification_version: 3
|
161
170
|
summary: Yet another option parsing library.
|
162
|
-
test_files:
|
163
|
-
|
164
|
-
- examples/foo.rb
|
165
|
-
- examples/superfoo.rb
|
166
|
-
- spec/choosy/argument_spec.rb
|
167
|
-
- spec/choosy/base_command_spec.rb
|
168
|
-
- spec/choosy/command_spec.rb
|
169
|
-
- spec/choosy/converter_spec.rb
|
170
|
-
- spec/choosy/dsl/argument_builder_spec.rb
|
171
|
-
- spec/choosy/dsl/base_builder_spec.rb
|
172
|
-
- spec/choosy/dsl/base_command_builder_spec.rb
|
173
|
-
- spec/choosy/dsl/commmand_builder_spec.rb
|
174
|
-
- spec/choosy/dsl/option_builder_spec.rb
|
175
|
-
- spec/choosy/dsl/super_command_builder_spec.rb
|
176
|
-
- spec/choosy/option_spec.rb
|
177
|
-
- spec/choosy/parser_spec.rb
|
178
|
-
- spec/choosy/printing/base_printer_spec.rb
|
179
|
-
- spec/choosy/printing/color_spec.rb
|
180
|
-
- spec/choosy/printing/help_printer_spec.rb
|
181
|
-
- spec/choosy/printing/manpage_printer_spec.rb
|
182
|
-
- spec/choosy/printing/manpage_spec.rb
|
183
|
-
- spec/choosy/printing/terminal_spec.rb
|
184
|
-
- spec/choosy/super_command_spec.rb
|
185
|
-
- spec/choosy/super_parser_spec.rb
|
186
|
-
- spec/choosy/verifier_spec.rb
|
187
|
-
- spec/choosy/version_spec.rb
|
188
|
-
- spec/integration/command-A_spec.rb
|
189
|
-
- spec/integration/command-B_spec.rb
|
190
|
-
- spec/integration/command-C_spec.rb
|
191
|
-
- spec/integration/supercommand-A_spec.rb
|
192
|
-
- spec/integration/supercommand-B_spec.rb
|
193
|
-
- spec/integration/supercommand-C_spec.rb
|
194
|
-
- spec/spec_helpers.rb
|
171
|
+
test_files: []
|
172
|
+
|
data/examples/bar.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
##-
|
3
|
-
BEGIN {$VERBOSE = true}
|
4
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
-
##+
|
6
|
-
# bar.rb
|
7
|
-
require 'choosy'
|
8
|
-
|
9
|
-
# Create a new command
|
10
|
-
$bar_cmd = Choosy::Command.new :bar do
|
11
|
-
executor do |args, options|
|
12
|
-
if options[:bold]
|
13
|
-
puts "BOLD!!!"
|
14
|
-
else
|
15
|
-
puts "plain"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
summary "Displays when this is a subcommand"
|
20
|
-
para "Just prints 'bar'"
|
21
|
-
para "A truly unremarkable command"
|
22
|
-
|
23
|
-
header 'Option:'
|
24
|
-
boolean :bold, "Bolds something" do
|
25
|
-
negate 'un'
|
26
|
-
end
|
27
|
-
|
28
|
-
# Because there is no bar.arguments call,
|
29
|
-
# it is now an error if there are extra
|
30
|
-
# command line arguments to this command.
|
31
|
-
end
|
32
|
-
|
33
|
-
if __FILE__ == $0
|
34
|
-
args = ['--un-bold']
|
35
|
-
|
36
|
-
result = $bar_cmd.parse!(args)
|
37
|
-
|
38
|
-
require 'pp'
|
39
|
-
pp result.options[:bold] # => false
|
40
|
-
pp result.args # => []
|
41
|
-
|
42
|
-
$bar_cmd.execute!(args) # => 'plain'
|
43
|
-
|
44
|
-
args << 'should-throw-error'
|
45
|
-
$bar_cmd.execute!(args)
|
46
|
-
end
|
data/examples/foo.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
##-
|
3
|
-
BEGIN {$VERBOSE = true}
|
4
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
-
##+
|
6
|
-
# foo.rb
|
7
|
-
require 'choosy'
|
8
|
-
|
9
|
-
FOO_VERSION = '1.0.1'
|
10
|
-
|
11
|
-
class FooExecutor
|
12
|
-
def execute!(args, options)
|
13
|
-
puts "BOLDED!!" if options[:bold]
|
14
|
-
options[:count].times do
|
15
|
-
puts "#{options[:prefix]}#{options[:words].push('foo').join(',')}#{options[:suffix]}"
|
16
|
-
end
|
17
|
-
puts "and #{args.join ' '}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
$foo_cmd = Choosy::Command.new :foo do |foo|
|
22
|
-
# Add a class to do the execution when you call foo_cmd.execute!
|
23
|
-
# You can also use a proc that takes the options and the args, like:
|
24
|
-
# executor { |args, options| puts 'Hi!' }
|
25
|
-
executor FooExecutor.new
|
26
|
-
|
27
|
-
# When used as a subcommand, you need a summary for the help screen
|
28
|
-
summary "This is a nice command named 'foo'"
|
29
|
-
|
30
|
-
# You can add your custom printer by giving the
|
31
|
-
# full path to an ERB template file here.
|
32
|
-
# The default printer is :standard, but you can
|
33
|
-
# also use the builtin printer :erb, with the :tempates
|
34
|
-
# parameter to set the erb template you wish to use. The
|
35
|
-
# output can be colored or uncolored, though the
|
36
|
-
# default is colored.
|
37
|
-
printer :standard, :color => true, :header_styles => [:bold, :green]
|
38
|
-
|
39
|
-
para 'Prints out "foo" to the console'
|
40
|
-
para 'This is a long description of what foo is an how it works. This line will assuredly wrap the console at least once, since it it such a long line, but it will be wrapped automatically by the printer, above. If you want to, you can add write "printer :standard, :max_width => 80" to set the maximum column width that the printer will allow (not respected by ERB templates).'
|
41
|
-
|
42
|
-
header 'Required Options:' # Formatted according to the header_styles for the printer
|
43
|
-
|
44
|
-
# A shorthand for a common option type.
|
45
|
-
# It adds the '-p/--prefix PREFIX' infomation for you.
|
46
|
-
single :prefix, "A prefix for 'foo'" do
|
47
|
-
default '<'
|
48
|
-
required
|
49
|
-
end
|
50
|
-
|
51
|
-
# The long way to do the same thing as above, except with
|
52
|
-
# explicitly named dependencies
|
53
|
-
option :suffix => [:prefix] do
|
54
|
-
short '-s'
|
55
|
-
long '--suffix', 'SUFFIX'
|
56
|
-
desc 'A suffix for "foo"'
|
57
|
-
required
|
58
|
-
|
59
|
-
validate do |suffix, options|
|
60
|
-
if suffix == options[:prefix]
|
61
|
-
die "You can't matching prefixes and suffixes, you heathen!"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Just like the 'single' method above, except now it automatically
|
67
|
-
# requires/casts the argument to this flag into an integer. These commands
|
68
|
-
# also take an optional hash as the last argument, which can be used instead
|
69
|
-
# of a block.
|
70
|
-
integer :count, 'The number of times to repeat "foo"', :required => true
|
71
|
-
|
72
|
-
header 'Options:', :bold, :blue # Format this header differently, overrides 'header_styles'
|
73
|
-
|
74
|
-
option :words do
|
75
|
-
short '-w'
|
76
|
-
long '--words', 'WORDS+' # By default, the '+' at the end
|
77
|
-
# means that this takes multiple
|
78
|
-
# arguments. You put a '-' at
|
79
|
-
# the end of the argument list
|
80
|
-
# to stop parsing this option
|
81
|
-
# and allow for regular args.
|
82
|
-
desc "Other fun words to put in quotes"
|
83
|
-
|
84
|
-
# Sets the exact count of the number of arguments it accepts.
|
85
|
-
# also allowable are the single selectors :zero and :one.
|
86
|
-
# By default, the option 'WORDS+' sets the range to be
|
87
|
-
# {:at_least => 1, :at_most => 1000 }
|
88
|
-
count :at_least => 2, :at_most => 10
|
89
|
-
|
90
|
-
validate do |words, options|
|
91
|
-
words.each do |word|
|
92
|
-
if word !~ /\w+/
|
93
|
-
die "I can't print that: #{word}"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Alternatively, we could have done the following:
|
100
|
-
strings :words, "Other fun words to put in quotes" do
|
101
|
-
count 2..10
|
102
|
-
default []
|
103
|
-
validate do |words, options|
|
104
|
-
words.each do |word|
|
105
|
-
if word !~ /\w+/
|
106
|
-
die "I can't print that: #{word}"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
# Yet another shorthand notation for options, since they
|
113
|
-
# are boolean by default. Here, we add a negation to the
|
114
|
-
# long flag of the option, creating [-b|--bold|--un-bold] flags.
|
115
|
-
# By default, calling 'negate' in a block without an argument
|
116
|
-
# uses the '--no-' prefix instead.
|
117
|
-
boolean :bold, "Bold this option", :default => false, :negate => 'un'
|
118
|
-
|
119
|
-
# Tail options
|
120
|
-
|
121
|
-
# When any of the simpler notations are suffixed with a '_'
|
122
|
-
# character, the short option is always suppressed.
|
123
|
-
boolean_ :debug, "Prints out extra debugging output."
|
124
|
-
|
125
|
-
# The '_' characters are replaced with '-' in flags, so the
|
126
|
-
# following creates a '--[no-]color' flag.
|
127
|
-
boolean_ :color, "Turns on/off coloring in the output. Defalt is on." do
|
128
|
-
negate
|
129
|
-
default true
|
130
|
-
validate do
|
131
|
-
foo.entity.alter do
|
132
|
-
printer :standard, :colored => false
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Adds the standard -h/--help option.
|
138
|
-
# Should skip the '-h' flag if already set.
|
139
|
-
help # Automatically adds the description if not passed an argument. You can supply your own
|
140
|
-
|
141
|
-
# Adds the --version option.
|
142
|
-
version "Foo: #{FOO_VERSION}"
|
143
|
-
|
144
|
-
# Now, add some validation for any addtional arguments
|
145
|
-
# that are left over after the parsing the options.
|
146
|
-
arguments do
|
147
|
-
metaname 'ARGS'
|
148
|
-
count 1..10
|
149
|
-
validate do |args, options|
|
150
|
-
if args.empty?
|
151
|
-
die "You have to pass in empty arguments that do nothing!"
|
152
|
-
end
|
153
|
-
if args.count == 10
|
154
|
-
die "Whoa there! You're going argument crazy!"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
if __FILE__ == $0
|
161
|
-
# Parses and validates the options.
|
162
|
-
args = ['--prefix', '{',
|
163
|
-
'--suffix', '}',
|
164
|
-
'--words', 'high', 'there', 'you', '-',
|
165
|
-
# The '-' stops parsing this option, so that:
|
166
|
-
'handsom', 'devil',
|
167
|
-
'http://not.posting.here', # will be regular arguments
|
168
|
-
'-c', '3', # Count
|
169
|
-
'--', # Stops parsing all arguments
|
170
|
-
'-h', '--help', '-v', '--version' # Ignored
|
171
|
-
]
|
172
|
-
result = $foo_cmd.parse!(args)
|
173
|
-
|
174
|
-
require 'pp'
|
175
|
-
pp result[:prefix] # => '{'
|
176
|
-
pp result[:suffix] # => '}'
|
177
|
-
pp result[:count] # => 3
|
178
|
-
pp result[:bold] # => false
|
179
|
-
pp result[:words] # => ['high', 'there', 'you']
|
180
|
-
pp result.args # => ['handsom', 'devil',
|
181
|
-
# 'http://not.posting.here',
|
182
|
-
# '-h', '--help', '-v', '--version']
|
183
|
-
pp result.options # => {:prefix => '{', :suffix => '}'
|
184
|
-
# :count => 3, :bold => false,
|
185
|
-
# :words => ['high', 'there', 'you'],
|
186
|
-
# :debug => false, :color => true}
|
187
|
-
|
188
|
-
# Now, call the command that does the actual work.
|
189
|
-
# This passes the foo_cmd.options and the foo_cmd.args
|
190
|
-
# as arguments to the executors 'execute!' method.
|
191
|
-
#
|
192
|
-
# This allows you to easily associate command classes with
|
193
|
-
# commands, without resorting to a hash or combining
|
194
|
-
# execution logic with command parsing logic.
|
195
|
-
$foo_cmd.execute!(args) # {high,there,you,foo}
|
196
|
-
# {high,there,you,foo}
|
197
|
-
# {high,there,you,foo}
|
198
|
-
# and handsom devil http://not.posting.here -h --help -v --verbose
|
199
|
-
|
200
|
-
end
|
data/examples/superfoo.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
##-
|
3
|
-
BEGIN {$VERBOSE = true}
|
4
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
6
|
-
##+
|
7
|
-
|
8
|
-
# superfoo.rb
|
9
|
-
require 'choosy'
|
10
|
-
require 'foo'
|
11
|
-
require 'bar'
|
12
|
-
|
13
|
-
SUPERFOO_VERSION = "1.0.1"
|
14
|
-
|
15
|
-
superfoo = Choosy::SuperCommand.new :superfoo do
|
16
|
-
summary "This is a superfoo command"
|
17
|
-
para "Say something, dammit!"
|
18
|
-
|
19
|
-
# You can also add commands after instantiation.
|
20
|
-
# Note that, when added, these commands have their
|
21
|
-
# -h/--help/--version flags suppressed, so you'll
|
22
|
-
# need to add those flags here.
|
23
|
-
command $bar_cmd
|
24
|
-
command $foo_cmd
|
25
|
-
|
26
|
-
# Creates a 'help' command, message optional
|
27
|
-
help "Prints this help message"
|
28
|
-
|
29
|
-
# Create some global options that are parsed
|
30
|
-
# defore result options
|
31
|
-
|
32
|
-
# Here, check that a YAML file exists, and attempt
|
33
|
-
# to load it's parsed contents into this option.
|
34
|
-
# There is also a 'file' type that checks to see
|
35
|
-
# if the file exists. With both 'file' and 'yaml',
|
36
|
-
# if the file is missing, the option fails with an
|
37
|
-
# error.
|
38
|
-
yaml :Config, "Configure your superfoo with a YAML configuration file." do
|
39
|
-
default File.join(ENV['HOME'], '.superfoo.yml')
|
40
|
-
end
|
41
|
-
|
42
|
-
# Adds a global --version flag.
|
43
|
-
version "#{SUPERFOO_VERSION}"
|
44
|
-
end
|
45
|
-
|
46
|
-
if __FILE__ == $0
|
47
|
-
args = ['foo',
|
48
|
-
'-c', '5',
|
49
|
-
'--config', 'superfoo.yaml',
|
50
|
-
'--prefix', '{',
|
51
|
-
'--suffix', '}',
|
52
|
-
'cruft',
|
53
|
-
'bar',
|
54
|
-
'--bold']
|
55
|
-
|
56
|
-
result = superfoo.parse!(args)
|
57
|
-
|
58
|
-
require 'pp'
|
59
|
-
pp result[:Config] # => {:here => 'text'} # Pulled the config!
|
60
|
-
|
61
|
-
foores = result.subresults[0]
|
62
|
-
|
63
|
-
pp foores[:Config] # => {:here => 'text'} # Passed along!
|
64
|
-
pp foores[:prefix] # => '{'
|
65
|
-
pp foores[:suffix] # => '}'
|
66
|
-
pp foores[:count] # => 5
|
67
|
-
pp foores[:bold] # => true
|
68
|
-
pp foores.options # => {:prefix => '{', :suffix => '}'
|
69
|
-
# :count => 5,
|
70
|
-
# :bold => true,
|
71
|
-
# :words => [],
|
72
|
-
# :config => '~/.superfoo' }
|
73
|
-
pp foores.args # => ['cruft', 'bar']
|
74
|
-
|
75
|
-
# Now, we can call the result
|
76
|
-
superfoo.execute!(args) ## Calls superfoo.result.execute!
|
77
|
-
## Prints:
|
78
|
-
# BOLDED!!
|
79
|
-
# {foo}
|
80
|
-
# {foo,foo}
|
81
|
-
# {foo,foo,foo}
|
82
|
-
# {foo,foo,foo,foo}
|
83
|
-
# {foo,foo,foo,foo,foo}
|
84
|
-
# and cruft bar
|
85
|
-
|
86
|
-
# Instead of parsing the 'bar' parameter as an argument to
|
87
|
-
# the foo command, so that when the first argument that matches
|
88
|
-
# another command name is encountered, it stops parsing the
|
89
|
-
# current command and passes the rest of the arguments to the
|
90
|
-
# next command.
|
91
|
-
#
|
92
|
-
# In this case, we call the 'alter' method to use the DSL
|
93
|
-
# syntax again to alter this command.
|
94
|
-
#
|
95
|
-
# You can also set this inside a SuperChoosy.new {...}
|
96
|
-
# block.
|
97
|
-
superfoo.alter do
|
98
|
-
parsimonious
|
99
|
-
end
|
100
|
-
|
101
|
-
result = superfoo.parse!(args)
|
102
|
-
|
103
|
-
foores = result.subresults[0]
|
104
|
-
pp foores[:Config] # => {:here => 'text'} # Passed along!
|
105
|
-
pp foores.command.name # => :foo
|
106
|
-
pp foores[:prefix] # => '{'
|
107
|
-
pp foores[:suffix] # => '}'
|
108
|
-
pp foores[:count] # => 5
|
109
|
-
pp foores[:bold] # => true
|
110
|
-
pp foores.options # => {:prefix => '{', :suffix => '}'
|
111
|
-
# :count => 5,
|
112
|
-
# :bold => false,
|
113
|
-
# :words => [],
|
114
|
-
# :config => {:here => 'text'}
|
115
|
-
# }
|
116
|
-
pp foores.args # => ['cruft']
|
117
|
-
|
118
|
-
barres = result.subresults[1]
|
119
|
-
pp barres.command.name # => :bar
|
120
|
-
pp barres[:bold] # => true
|
121
|
-
pp barres.options # => {:bold => true,
|
122
|
-
# :config => {:here => 'text'}
|
123
|
-
# }
|
124
|
-
pp barres.args # => []
|
125
|
-
|
126
|
-
# Now, execute the results in order
|
127
|
-
superfoo.execute!(args) ## Same as:
|
128
|
-
# results.each do |subcommand|
|
129
|
-
# command.execute!
|
130
|
-
# end
|
131
|
-
## Prints:
|
132
|
-
# {foo}
|
133
|
-
# {foo}
|
134
|
-
# and cruft
|
135
|
-
# BOLDED BAR
|
136
|
-
end
|
137
|
-
|