escort 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.irbrc +2 -0
- data/.travis.yml +1 -1
- data/README.md +272 -3
- data/TODO.md +118 -71
- data/examples/.my_apprc +24 -0
- data/examples/basic_config_file +16 -0
- data/examples/basic_conflicts +1 -1
- data/examples/basic_with_everything +30 -0
- data/examples/suite_complex +65 -0
- data/examples/{command → suite_simple} +0 -0
- data/examples/suite_with_sub_commands +94 -0
- data/lib/escort.rb +6 -4
- data/lib/escort/action_command/base.rb +7 -5
- data/lib/escort/app.rb +2 -8
- data/lib/escort/auto_options.rb +5 -3
- data/lib/escort/formatter/cursor_position.rb +29 -0
- data/lib/escort/formatter/default_help_formatter.rb +37 -32
- data/lib/escort/formatter/option.rb +1 -1
- data/lib/escort/formatter/stream_output_formatter.rb +88 -0
- data/lib/escort/formatter/{borderless_table.rb → string_grid.rb} +21 -19
- data/lib/escort/formatter/string_splitter.rb +24 -4
- data/lib/escort/setup/configuration/loader.rb +8 -2
- data/lib/escort/setup/configuration/locator/chaining.rb +29 -0
- data/lib/escort/setup/configuration/locator/executing_script_directory.rb +15 -0
- data/lib/escort/setup/configuration/locator/specified_directory.rb +21 -0
- data/lib/escort/setup/configuration/reader.rb +4 -2
- data/lib/escort/setup/configuration/writer.rb +6 -2
- data/lib/escort/setup/dsl/command.rb +7 -8
- data/lib/escort/setup/dsl/global.rb +3 -51
- data/lib/escort/version.rb +1 -1
- data/spec/integration/basic_config_file_spec.rb +82 -0
- data/spec/integration/suite_simple_spec.rb +45 -0
- data/spec/integration/suite_sub_command_spec.rb +51 -0
- data/spec/lib/escort/action_command/base_spec.rb +200 -0
- data/spec/lib/escort/formatter/option_spec.rb +2 -2
- data/spec/lib/escort/formatter/stream_output_formatter_spec.rb +214 -0
- data/spec/lib/escort/formatter/string_grid_spec.rb +59 -0
- data/spec/lib/escort/setup/configuration/generator_spec.rb +101 -0
- data/spec/lib/escort/setup/configuration/loader_spec.rb +79 -0
- data/spec/lib/escort/setup/configuration/locator/chaining_spec.rb +81 -0
- data/spec/lib/escort/setup/configuration/locator/descending_to_home_spec.rb +57 -0
- data/spec/lib/escort/setup/configuration/locator/executing_script_directory_spec.rb +29 -0
- data/spec/lib/escort/setup/configuration/locator/specified_directory_spec.rb +33 -0
- data/spec/lib/escort/setup/configuration/merge_tool_spec.rb +41 -0
- data/spec/lib/escort/setup/configuration/reader_spec.rb +41 -0
- data/spec/lib/escort/setup/configuration/writer_spec.rb +75 -0
- data/spec/spec_helper.rb +2 -1
- metadata +44 -24
- data/examples/attic/1_1_basic.rb +0 -15
- data/examples/attic/1_2_basic_requires_arguments.rb +0 -15
- data/examples/attic/2_2_command.rb +0 -18
- data/examples/attic/2_2_command_requires_arguments.rb +0 -20
- data/examples/attic/2_3_nested_commands.rb +0 -26
- data/examples/attic/3_validations.rb +0 -31
- data/examples/attic/4_1_config_file.rb +0 -42
- data/examples/attic/argument_handling/basic.rb +0 -12
- data/examples/attic/argument_handling/basic_command.rb +0 -18
- data/examples/attic/argument_handling/no_arguments.rb +0 -14
- data/examples/attic/argument_handling/no_arguments_command.rb +0 -20
- data/examples/attic/command_aliases/app.rb +0 -31
- data/examples/attic/config_file/.apprc2 +0 -16
- data/examples/attic/config_file/app.rb +0 -78
- data/examples/attic/config_file/sub_commands.rb +0 -35
- data/examples/attic/default_command/app.rb +0 -20
- data/examples/attic/sub_commands/app.rb +0 -18
- data/examples/attic/validation_basic/app.rb +0 -31
- data/lib/escort/formatter/terminal_formatter.rb +0 -58
- data/lib/escort/setup/dsl/validations.rb +0 -25
@@ -0,0 +1,41 @@
|
|
1
|
+
describe Escort::Setup::Configuration::Reader do
|
2
|
+
include FakeFS::SpecHelpers
|
3
|
+
|
4
|
+
let(:reader) {Escort::Setup::Configuration::Reader.new(path)}
|
5
|
+
let(:path) {'/usr/alan/blah.json'}
|
6
|
+
let(:data) { {:hello => :world} }
|
7
|
+
|
8
|
+
describe "#read" do
|
9
|
+
subject {reader.read}
|
10
|
+
|
11
|
+
context "when path not given" do
|
12
|
+
let(:path) {nil}
|
13
|
+
it{subject.should be_empty}
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when configuration file not present" do
|
17
|
+
before do
|
18
|
+
FileUtils.mkdir_p(File.dirname path)
|
19
|
+
end
|
20
|
+
it{subject.should be_empty}
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when configuration file not JSON" do
|
24
|
+
before do
|
25
|
+
FileUtils.mkdir_p(File.dirname path)
|
26
|
+
File.open(path, 'w') {|f| f.write("hello") }
|
27
|
+
end
|
28
|
+
it{subject.should be_empty}
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when configuration file present" do
|
32
|
+
let(:config_data) { {:hello => :blah} }
|
33
|
+
|
34
|
+
before do
|
35
|
+
FileUtils.mkdir_p(File.dirname path)
|
36
|
+
File.open(path, 'w') {|f| f.write(JSON.pretty_generate(config_data)) }
|
37
|
+
end
|
38
|
+
it {subject.data.should == {:hello => "blah"}}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
describe Escort::Setup::Configuration::Writer do
|
2
|
+
include FakeFS::SpecHelpers
|
3
|
+
let(:writer) {Escort::Setup::Configuration::Writer.new(path, data)}
|
4
|
+
let(:path) {'/usr/alan/blah.json'}
|
5
|
+
let(:data) { {:hello => :world} }
|
6
|
+
|
7
|
+
describe "#write" do
|
8
|
+
subject {writer.write}
|
9
|
+
|
10
|
+
context "when path is nil" do
|
11
|
+
let(:path) {nil}
|
12
|
+
it {subject.should be_empty}
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when path is not nil" do
|
16
|
+
context "and the file does not exist" do
|
17
|
+
it {subject.should_not be_empty}
|
18
|
+
it {subject.path.should == path}
|
19
|
+
it {subject.data.should == data}
|
20
|
+
it("file should have the right contents") do
|
21
|
+
subject
|
22
|
+
json = File.read(path)
|
23
|
+
hash = ::JSON.parse(json)
|
24
|
+
actual_data = Escort::Utils.symbolize_keys(hash)
|
25
|
+
actual_data.should == {:hello => "world"}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and the file already exists" do
|
30
|
+
before do
|
31
|
+
FileUtils.mkdir_p(File.dirname path)
|
32
|
+
FileUtils.touch(path)
|
33
|
+
end
|
34
|
+
it {subject.should be_empty}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#update" do
|
40
|
+
subject {writer.update}
|
41
|
+
|
42
|
+
context "when file does not exist" do
|
43
|
+
it {subject.should_not be_empty}
|
44
|
+
it {subject.path.should == path}
|
45
|
+
it {subject.data.should == data}
|
46
|
+
it("file should have the right contents") do
|
47
|
+
subject
|
48
|
+
json = File.read(path)
|
49
|
+
hash = ::JSON.parse(json)
|
50
|
+
actual_data = Escort::Utils.symbolize_keys(hash)
|
51
|
+
actual_data.should == {:hello => "world"}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when file does exit" do
|
56
|
+
let(:previous_data) { {:hello => :blah} }
|
57
|
+
let(:data) { {:hello => :world, :foo => :bar} }
|
58
|
+
before do
|
59
|
+
FileUtils.mkdir_p(File.dirname path)
|
60
|
+
File.open(path, 'w') {|f| f.write(JSON.pretty_generate(previous_data)) }
|
61
|
+
end
|
62
|
+
|
63
|
+
it {subject.should_not be_empty}
|
64
|
+
it {subject.path.should == path}
|
65
|
+
it {subject.data.should == data}
|
66
|
+
it("file should have the right contents") do
|
67
|
+
subject
|
68
|
+
json = File.read(path)
|
69
|
+
hash = ::JSON.parse(json)
|
70
|
+
actual_data = Escort::Utils.symbolize_keys(hash)
|
71
|
+
actual_data.should == {:hello=>"blah", :foo=>"bar"}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Skorkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -87,25 +87,9 @@ files:
|
|
87
87
|
- Rakefile
|
88
88
|
- TODO.md
|
89
89
|
- escort.gemspec
|
90
|
-
- examples
|
91
|
-
- examples/attic/1_2_basic_requires_arguments.rb
|
92
|
-
- examples/attic/2_2_command.rb
|
93
|
-
- examples/attic/2_2_command_requires_arguments.rb
|
94
|
-
- examples/attic/2_3_nested_commands.rb
|
95
|
-
- examples/attic/3_validations.rb
|
96
|
-
- examples/attic/4_1_config_file.rb
|
97
|
-
- examples/attic/argument_handling/basic.rb
|
98
|
-
- examples/attic/argument_handling/basic_command.rb
|
99
|
-
- examples/attic/argument_handling/no_arguments.rb
|
100
|
-
- examples/attic/argument_handling/no_arguments_command.rb
|
101
|
-
- examples/attic/command_aliases/app.rb
|
102
|
-
- examples/attic/config_file/.apprc2
|
103
|
-
- examples/attic/config_file/app.rb
|
104
|
-
- examples/attic/config_file/sub_commands.rb
|
105
|
-
- examples/attic/default_command/app.rb
|
106
|
-
- examples/attic/sub_commands/app.rb
|
107
|
-
- examples/attic/validation_basic/app.rb
|
90
|
+
- examples/.my_apprc
|
108
91
|
- examples/basic
|
92
|
+
- examples/basic_config_file
|
109
93
|
- examples/basic_conflicts
|
110
94
|
- examples/basic_depends_on
|
111
95
|
- examples/basic_flags
|
@@ -114,8 +98,11 @@ files:
|
|
114
98
|
- examples/basic_require_arguments
|
115
99
|
- examples/basic_texts
|
116
100
|
- examples/basic_validations
|
117
|
-
- examples/
|
101
|
+
- examples/basic_with_everything
|
118
102
|
- examples/commands/example_command.rb
|
103
|
+
- examples/suite_complex
|
104
|
+
- examples/suite_simple
|
105
|
+
- examples/suite_with_sub_commands
|
119
106
|
- lib/escort.rb
|
120
107
|
- lib/escort/action_command/base.rb
|
121
108
|
- lib/escort/action_command/escort_utility_command.rb
|
@@ -123,17 +110,18 @@ files:
|
|
123
110
|
- lib/escort/arguments.rb
|
124
111
|
- lib/escort/auto_options.rb
|
125
112
|
- lib/escort/error/error.rb
|
126
|
-
- lib/escort/formatter/borderless_table.rb
|
127
113
|
- lib/escort/formatter/command.rb
|
128
114
|
- lib/escort/formatter/commands.rb
|
115
|
+
- lib/escort/formatter/cursor_position.rb
|
129
116
|
- lib/escort/formatter/default_help_formatter.rb
|
130
117
|
- lib/escort/formatter/global_command.rb
|
131
118
|
- lib/escort/formatter/option.rb
|
132
119
|
- lib/escort/formatter/options.rb
|
133
120
|
- lib/escort/formatter/shell_command_executor.rb
|
121
|
+
- lib/escort/formatter/stream_output_formatter.rb
|
122
|
+
- lib/escort/formatter/string_grid.rb
|
134
123
|
- lib/escort/formatter/string_splitter.rb
|
135
124
|
- lib/escort/formatter/terminal.rb
|
136
|
-
- lib/escort/formatter/terminal_formatter.rb
|
137
125
|
- lib/escort/global_pre_parser.rb
|
138
126
|
- lib/escort/logger.rb
|
139
127
|
- lib/escort/option_dependency_validator.rb
|
@@ -142,7 +130,10 @@ files:
|
|
142
130
|
- lib/escort/setup/configuration/instance.rb
|
143
131
|
- lib/escort/setup/configuration/loader.rb
|
144
132
|
- lib/escort/setup/configuration/locator/base.rb
|
133
|
+
- lib/escort/setup/configuration/locator/chaining.rb
|
145
134
|
- lib/escort/setup/configuration/locator/descending_to_home.rb
|
135
|
+
- lib/escort/setup/configuration/locator/executing_script_directory.rb
|
136
|
+
- lib/escort/setup/configuration/locator/specified_directory.rb
|
146
137
|
- lib/escort/setup/configuration/merge_tool.rb
|
147
138
|
- lib/escort/setup/configuration/reader.rb
|
148
139
|
- lib/escort/setup/configuration/writer.rb
|
@@ -151,12 +142,12 @@ files:
|
|
151
142
|
- lib/escort/setup/dsl/config_file.rb
|
152
143
|
- lib/escort/setup/dsl/global.rb
|
153
144
|
- lib/escort/setup/dsl/options.rb
|
154
|
-
- lib/escort/setup/dsl/validations.rb
|
155
145
|
- lib/escort/setup_accessor.rb
|
156
146
|
- lib/escort/trollop.rb
|
157
147
|
- lib/escort/utils.rb
|
158
148
|
- lib/escort/validator.rb
|
159
149
|
- lib/escort/version.rb
|
150
|
+
- spec/integration/basic_config_file_spec.rb
|
160
151
|
- spec/integration/basic_conflicts_spec.rb
|
161
152
|
- spec/integration/basic_depends_on_spec.rb
|
162
153
|
- spec/integration/basic_options_spec.rb
|
@@ -165,12 +156,26 @@ files:
|
|
165
156
|
- spec/integration/basic_validations_spec.rb
|
166
157
|
- spec/integration/basic_with_arguments_spec.rb
|
167
158
|
- spec/integration/basic_with_text_fields_spec.rb
|
159
|
+
- spec/integration/suite_simple_spec.rb
|
160
|
+
- spec/integration/suite_sub_command_spec.rb
|
161
|
+
- spec/lib/escort/action_command/base_spec.rb
|
168
162
|
- spec/lib/escort/formatter/command_spec.rb
|
169
163
|
- spec/lib/escort/formatter/global_command_spec.rb
|
170
164
|
- spec/lib/escort/formatter/option_spec.rb
|
171
165
|
- spec/lib/escort/formatter/shell_command_executor_spec.rb
|
166
|
+
- spec/lib/escort/formatter/stream_output_formatter_spec.rb
|
167
|
+
- spec/lib/escort/formatter/string_grid_spec.rb
|
172
168
|
- spec/lib/escort/formatter/string_splitter_spec.rb
|
173
169
|
- spec/lib/escort/formatter/terminal_spec.rb
|
170
|
+
- spec/lib/escort/setup/configuration/generator_spec.rb
|
171
|
+
- spec/lib/escort/setup/configuration/loader_spec.rb
|
172
|
+
- spec/lib/escort/setup/configuration/locator/chaining_spec.rb
|
173
|
+
- spec/lib/escort/setup/configuration/locator/descending_to_home_spec.rb
|
174
|
+
- spec/lib/escort/setup/configuration/locator/executing_script_directory_spec.rb
|
175
|
+
- spec/lib/escort/setup/configuration/locator/specified_directory_spec.rb
|
176
|
+
- spec/lib/escort/setup/configuration/merge_tool_spec.rb
|
177
|
+
- spec/lib/escort/setup/configuration/reader_spec.rb
|
178
|
+
- spec/lib/escort/setup/configuration/writer_spec.rb
|
174
179
|
- spec/lib/escort/setup_accessor_spec.rb
|
175
180
|
- spec/lib/escort/utils_spec.rb
|
176
181
|
- spec/spec_helper.rb
|
@@ -205,6 +210,7 @@ specification_version: 4
|
|
205
210
|
summary: A library that makes building command line apps in ruby so easy, you'll feel
|
206
211
|
like an expert is guiding you through it
|
207
212
|
test_files:
|
213
|
+
- spec/integration/basic_config_file_spec.rb
|
208
214
|
- spec/integration/basic_conflicts_spec.rb
|
209
215
|
- spec/integration/basic_depends_on_spec.rb
|
210
216
|
- spec/integration/basic_options_spec.rb
|
@@ -213,12 +219,26 @@ test_files:
|
|
213
219
|
- spec/integration/basic_validations_spec.rb
|
214
220
|
- spec/integration/basic_with_arguments_spec.rb
|
215
221
|
- spec/integration/basic_with_text_fields_spec.rb
|
222
|
+
- spec/integration/suite_simple_spec.rb
|
223
|
+
- spec/integration/suite_sub_command_spec.rb
|
224
|
+
- spec/lib/escort/action_command/base_spec.rb
|
216
225
|
- spec/lib/escort/formatter/command_spec.rb
|
217
226
|
- spec/lib/escort/formatter/global_command_spec.rb
|
218
227
|
- spec/lib/escort/formatter/option_spec.rb
|
219
228
|
- spec/lib/escort/formatter/shell_command_executor_spec.rb
|
229
|
+
- spec/lib/escort/formatter/stream_output_formatter_spec.rb
|
230
|
+
- spec/lib/escort/formatter/string_grid_spec.rb
|
220
231
|
- spec/lib/escort/formatter/string_splitter_spec.rb
|
221
232
|
- spec/lib/escort/formatter/terminal_spec.rb
|
233
|
+
- spec/lib/escort/setup/configuration/generator_spec.rb
|
234
|
+
- spec/lib/escort/setup/configuration/loader_spec.rb
|
235
|
+
- spec/lib/escort/setup/configuration/locator/chaining_spec.rb
|
236
|
+
- spec/lib/escort/setup/configuration/locator/descending_to_home_spec.rb
|
237
|
+
- spec/lib/escort/setup/configuration/locator/executing_script_directory_spec.rb
|
238
|
+
- spec/lib/escort/setup/configuration/locator/specified_directory_spec.rb
|
239
|
+
- spec/lib/escort/setup/configuration/merge_tool_spec.rb
|
240
|
+
- spec/lib/escort/setup/configuration/reader_spec.rb
|
241
|
+
- spec/lib/escort/setup/configuration/writer_spec.rb
|
222
242
|
- spec/lib/escort/setup_accessor_spec.rb
|
223
243
|
- spec/lib/escort/utils_spec.rb
|
224
244
|
- spec/spec_helper.rb
|
data/examples/attic/1_1_basic.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.version "0.2.5"
|
6
|
-
|
7
|
-
app.options do |opts|
|
8
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
9
|
-
opts.opt :multi_option, "Option that can be specified multiple times alksjdfh lakjdfh adf alksdfh alkdfjh alsdfjhaskdjfh alsdkfjh alksfdjh akdfjh alkdsjf alksdjfh alksdfjh asdfjklh aslkdfhj aslkdfjh adfjkhl", :short => '-m', :long => '--multi', :type => :string, :multi => true
|
10
|
-
end
|
11
|
-
|
12
|
-
app.action do |options, arguments|
|
13
|
-
puts "Action \nglobal options: #{options} \narguments: #{arguments}"
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.requires_arguments
|
6
|
-
|
7
|
-
app.options do |opts|
|
8
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
9
|
-
opts.opt :multi_option, "Option that can be specified multiple times alksjdfh lakjdfh adf alksdfh alkdfjh alsdfjhaskdjfh alsdkfjh alksfdjh akdfjh alkdsjf alksdjfh alksdfjh asdfjklh aslkdfhj aslkdfjh adfjkhl", :short => '-m', :long => '--multi', :type => :string, :multi => true
|
10
|
-
end
|
11
|
-
|
12
|
-
app.action do |options, arguments|
|
13
|
-
puts "Action \nglobal options: #{options} \narguments: #{arguments}"
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.options do |opts|
|
6
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
7
|
-
end
|
8
|
-
|
9
|
-
app.command :my_command, :description => "KJHLKJH askj aldkjfhakldfjh akdjfh alkdfhj alkdjhf alkjsdhf alkjsdhf aklsjdhf aklsjdhf akljdhf alkdjfh" do |command|
|
10
|
-
command.options do |opts|
|
11
|
-
opts.opt :do_stuff, "Do stuff", :short => :none, :long => '--do-stuff', :type => :boolean, :default => true
|
12
|
-
end
|
13
|
-
|
14
|
-
command.action do |options, arguments|
|
15
|
-
puts "Action for my_command\noptions: #{options} \narguments: #{arguments}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.options do |opts|
|
6
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
7
|
-
end
|
8
|
-
|
9
|
-
app.command :my_command, :description => "KJHLKJH askj aldkjfhakldfjh akdjfh alkdfhj alkdjhf alkjsdhf alkjsdhf aklsjdhf aklsjdhf akljdhf alkdjfh" do |command|
|
10
|
-
command.requires_arguments
|
11
|
-
|
12
|
-
command.options do |opts|
|
13
|
-
opts.opt :do_stuff, "Do stuff", :short => :none, :long => '--do-stuff', :type => :boolean, :default => true
|
14
|
-
end
|
15
|
-
|
16
|
-
command.action do |options, arguments|
|
17
|
-
puts "Action for my_command\noptions: #{options} \narguments: #{arguments}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.options do |opts|
|
6
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
7
|
-
end
|
8
|
-
|
9
|
-
app.command :my_command, :description => "KJHLKJH askj aldkjfhakldfjh akdjfh alkdfhj alkdjhf alkjsdhf alkjsdhf aklsjdhf aklsjdhf akljdhf alkdjfh" do |command|
|
10
|
-
command.requires_arguments
|
11
|
-
|
12
|
-
command.options do |opts|
|
13
|
-
opts.opt :do_stuff, "Do stuff", :short => :none, :long => '--do-stuff', :type => :boolean, :default => true
|
14
|
-
end
|
15
|
-
|
16
|
-
command.action do |options, arguments|
|
17
|
-
puts "Action for my_command\noptions: #{options} \narguments: #{arguments}"
|
18
|
-
end
|
19
|
-
|
20
|
-
command.command :nested_command, :description => "A nested sub command" do |command|
|
21
|
-
command.action do |options, arguments|
|
22
|
-
puts "Action for my_command nested_command\noptions: #{options} \narguments: #{arguments}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.options do |opts|
|
6
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
7
|
-
opts.opt :multi_option, "Option that can be specified multiple times", :short => '-m', :long => '--multi', :type => :string, :multi => true
|
8
|
-
opts.opt :a_number, "Do stuff", :short => "-n", :long => '--number', :type => :int
|
9
|
-
end
|
10
|
-
|
11
|
-
app.validations do |opts|
|
12
|
-
opts.validate(:global_option, "must be either 'global' or 'local'") { |option| ["global", "local"].include?(option) }
|
13
|
-
opts.validate(:a_number, "must be between 10 and 20 exclusive") { |option| option > 10 && option < 20 }
|
14
|
-
end
|
15
|
-
|
16
|
-
app.command :my_command do |command|
|
17
|
-
command.options do |opts|
|
18
|
-
opts.opt :do_stuff, "Do stuff", :short => :none, :long => '--do-stuff', :type => :boolean, :default => true
|
19
|
-
opts.opt :string_with_format, "String with format", :short => "-f", :long => '--format', :type => :string, :default => "blah yadda11111111111"
|
20
|
-
end
|
21
|
-
|
22
|
-
command.validations do |opts|
|
23
|
-
opts.validate(:string_with_format, "should be at least two words") {|option| option =~ /\w\s\w/}
|
24
|
-
opts.validate(:string_with_format, "should be at least 20 characters long") {|option| option.length >= 20}
|
25
|
-
end
|
26
|
-
|
27
|
-
command.action do |options, arguments|
|
28
|
-
puts "Action for my_command\noptions: #{options} \narguments: #{arguments}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "escort"))
|
3
|
-
|
4
|
-
Escort::App.create do |app|
|
5
|
-
app.options do |opts|
|
6
|
-
opts.opt :global_option, "Global option", :short => '-g', :long => '--global', :type => :string, :default => "global"
|
7
|
-
opts.opt :multi_option, "Option that can be specified multiple times alksjdfh lakjdfh adf alksdfh alkdfjh alsdfjhaskdjfh alsdkfjh alksfdjh akdfjh alkdsjf alksdjfh alksdfjh asdfjklh aslkdfhj aslkdfjh adfjkhl", :short => '-m', :long => '--multi', :type => :string, :multi => true
|
8
|
-
end
|
9
|
-
|
10
|
-
app.config_file ".apprc", :autocreate => true
|
11
|
-
|
12
|
-
app.summary "Sum1"
|
13
|
-
app.description "Desc1"
|
14
|
-
|
15
|
-
app.command :my_command, :description => "KJHLKJH askj aldkjfhakldfjh akdjfh alkdfhj alkdjhf alkjsdhf alkjsdhf aklsjdhf aklsjdhf akljdhf alkdjfh", :aliases => [:my1, :my2] do |command|
|
16
|
-
#command.requires_arguments
|
17
|
-
command.summary "Sum2"
|
18
|
-
command.description "Desc2"
|
19
|
-
|
20
|
-
command.options do |opts|
|
21
|
-
opts.opt :do_stuff, "Do stuff", :short => :none, :long => '--do-stuff', :type => :boolean, :default => true
|
22
|
-
end
|
23
|
-
|
24
|
-
command.action do |options, arguments|
|
25
|
-
puts "Action for my_command\noptions: #{options} \narguments: #{arguments}"
|
26
|
-
end
|
27
|
-
|
28
|
-
command.command :nested_command, :description => "A nested sub command" do |command|
|
29
|
-
command.options do |opts|
|
30
|
-
opts.opt :do_stuff, "Do stuff", :short => :none, :long => '--do-stuff', :type => :boolean, :default => true
|
31
|
-
end
|
32
|
-
|
33
|
-
command.action do |options, arguments|
|
34
|
-
puts "Action for my_command nested_command\noptions: #{options} \narguments: #{arguments}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
app.action do |options, arguments, config|
|
40
|
-
puts "Action \nglobal options: #{options} \narguments: #{arguments}\nconfig: #{config}"
|
41
|
-
end
|
42
|
-
end
|