escort 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzQ3YWNjMzdhYWVmMjJiNThhYmFkNDlmYTdhZjRiOTk1MTE5MjU0OA==
5
- data.tar.gz: !binary |-
6
- MDA2MDVmNGQ5M2I2ODRlNGUzODU5YzgzYjI1ZTY3NjU2YzRjMmNiMg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZjBiNWM4N2MyMDQ3NDI2ZmQyZjI4NjBmZjg3YmZhZTRjNGU5ZDFlNjljYzYw
10
- Y2Q0MThjMDQyYTg5YjAzZWE3ZDQ2NGFhZWIwZDE0MjU2MTZiZTk5MDdmZGVl
11
- MWVmMTUzMTYzODc5NzcxYmEyZmE5MGI4NmNlNjI3MThkMWEyMDI=
12
- data.tar.gz: !binary |-
13
- ODkwMzNlN2Q0NTMwOGY2ZGQzYTA3YjA3ZTNiMjdkYTgzMjBmYmI1ZTVjNDQy
14
- ZTM0ZGU2ZGZjNmVhYjhiMjdmZTVjY2NiNGY2ZGRmNmUzMTcyNmViMzNmYjQ4
15
- NzQzN2MxMjlhOGFiN2UxZGE2ODc2MWZmY2IxODAzNjFkM2ViMmQ=
2
+ SHA1:
3
+ metadata.gz: f31a0746ef3bb6c559b04f55e87fa8e48900f32c
4
+ data.tar.gz: 236d3d50f9e7ac297dbb444e44e6628329aacba1
5
+ SHA512:
6
+ metadata.gz: 44545a6c19ecde7615c819c702744af2bd0810e5df6a755ce3fbc644b1c4a7154317da87a4c3c944cfbf3614799b3d76be0e6736fe58927c407961ae5532e83f
7
+ data.tar.gz: f8ffe0f3f296f16ca3f8d709a4101e746d505b321c5a42ec3280d48293e96f8414472184bfe546bab4e184a4adb9cd94119a5a1ab622e28a7279491859d90197
@@ -0,0 +1 @@
1
+ 2.0.0-p0
data/README.md CHANGED
@@ -684,7 +684,10 @@ TODO
684
684
 
685
685
  ## Command-Line Tools Built With Escort
686
686
 
687
- TODO
687
+ If you've used Escort to build a command-line tool that you have made publicly available, feel free to add a link to it here.
688
+
689
+ * https://github.com/skorks/ppjson - pretty print your JSON on the command-line (works with JSON strings as well as files containing JSON, can uglify as well as pretty print)
690
+
688
691
 
689
692
  ## Alternatives
690
693
 
data/TODO.md CHANGED
@@ -1,88 +1,24 @@
1
1
  ROADMAP
2
-
3
- v0.3.0
4
- - tag and release
5
-
6
-
7
- - up the version to 0.3.0 DONE
8
- - test the base command for actions well DONE
9
- - BUG parent_options when parent of command is global context doesn't seem to work??? DONE
10
- - integration test for commands DONE
11
- - integration test for sub-commands DONE
12
- - readme a basic app with config file, integration test (don't worry about explaining all the helper stuff that gets created) DONE
13
- - test the configuration loader DONE
14
- - test the descend to home locator DONE
15
- - test the configuration merge tool DONE
16
- - test the configuration generator DONE
17
- - test all the locators (descend, specfic dir, current script dir, chaining) DONE
18
- - we should always be using the chaining locator, with more or less sub locators depending on setup DONE
19
- - create other locators (dir of currently executing script locator, i.e. not the working directory, specified dir locator) DONE
20
- - create a chaining locator so we can put all our locators together DONE
21
- - test the configuration reader DONE
22
- - test the configuration writer DONE
23
- - a basic app example with all the trimmings DONE
24
- - app with config file example DONE
25
- - readme implementing and action for a basic app DONE
26
- - rejig for betterness the validations help outputs DONE
27
- - test the string grid DONE
28
- - start using the new stream output formatter DONE
29
- - refactor terminal formatter and test it DONE
30
- - finish testing the output formatter DONE
31
- - get rid of shell command executor new shell stuff (doesn't work in Jruby and not really needed anyway) DONE
32
- - extract all the dsl command stuff into a helper module so that global and command can be handled by the same code DONE
33
-
34
- v0.4.0
35
- - test all the config file helper stuff
36
- - a few more tests (setup accessor, all the dsl classes)
37
- - fix ppjson so that dependency suport feature is actually used
38
- - up the version to 0.4.0
39
- - tag and release
40
-
41
-
42
- - delete the stuff from the attic once it is no longer needed DONE
43
- - readme a sub command app with options, validations, description, summary, require arguments and config file, integration tests, example DONE
44
- - readme for requires arguments overriding and inheritance DONE
45
- - readme explain all the helper stuff that automatically gets created with config file support DONE
46
-
47
-
48
2
  v1.0.0
49
- - have a think about how to make the integration tests a bit more robust, so that failures don't get swallowed (test for specific exit codes instead of non-zero exit code), fix the existing integration tests
50
- - a few more integration tests (test that basic app automatically gets help and other automatic options)
51
- - clean up all the extraneous branches
3
+ - thoroughly test the setup accessor
4
+ - refactor setup accessor to break it up into multiple objects so that it is easier to test and less monolithic
5
+ - pull out the action execution into a separate class and test it
6
+ - a way have helpers available when you don't want to have to create a command
7
+ - readme about how to actually pass the user config through to action and the fact that regardless if you have a config file or not, you can have a config var or not as part of the block variables
52
8
  - up the version to 1.0.0
53
9
  - tag and release
54
- - get the blog updated with a new theme
55
- - put a new subscriber count widget on blog
56
- - blog Build Command-Line Apps Like a Pro Using Ruby and Escort
57
10
 
58
11
 
59
- - in trollop when errors are raised they should be wrapped as escort errors and propagate rather than being caught by trollop itself DONE
60
- - rework the examples again to show of some/most of the features (along the lines of the integration tests and readme) DONE
61
- - errors coming straigh out of configuration should still be caught by error handlers to only display stack trace when needed (refactor app create method) DONE
62
- - readme for a basic app with conflicting options DONE
63
- - readme for a basic app with dependent options DONE
64
12
 
65
13
  v1.0.1
66
- - pull out the action execution into a separate class and test it
67
- - add a section to readme for command line tools built with escort (e.g. ppjson)
68
- - more specs (all the dsl classes possibly)
69
- - more integration specs (more specs for the different types of options)
70
- - a way have helpers available when you don't want to have to create a command
71
- - the config auto option should not be included in the config file, same with other auto options???
72
- - readme about how to actually pass the user config through to action and the fact that regardless if you have a config file or not, you can have a config var or not as part of the block variables
73
-
74
-
75
- - rework the integration specs and matchers so there are less moving parts (perhaps push some stuff down into a base class etc.) DONE
76
- - rewrite the help formatter to be a bit easier to understand (more like man output for output) DONE
77
- - add depends support to dsl DONE
78
14
 
79
15
  v1.0.2
16
+ - create a table of contents for the readme so that it is easier to navigate it
80
17
  - refactor the app class so it is a bit nicer etc
81
- - more specs
82
18
  - need a suite for escort itself using escort to bootstrap etc
83
- - scaffold for app with no sub commands
84
- - scaffold for app with one level of commands
85
- - scaffold for app with nested sub commands
19
+ - scaffold for app with no sub commands (escort g -o blah -o yadda bin/app.rb)
20
+ - scaffold for app with one level of commands (escort g -o blah -o yadda suite -o blah -o yadda -c foo -c bar bin/app.rb)
21
+ - scaffold for app with nested sub commands (escort g -o blah -o yadda suite -o blah -o yadda -c foo -c bar --nested bin/app.rb) ???
86
22
 
87
23
  v1.0.3
88
24
  - an option for setup that indicates it is a project specific CLI app
@@ -90,8 +26,7 @@ v1.0.3
90
26
  - make the configuration environment aware
91
27
  - make escort environment aware (app.environment_aware)
92
28
  - json configuration should support defaults config
93
- - pull the terminal formatting stuff into separate gem
94
- - pull nested exception stuff into separate gem
29
+ - if necessary, extra helpers to work with environment specific config sections (xxx -e production escort --create-config-environment-section)
95
30
 
96
31
 
97
32
  - much better documentation and usage patterns DONE
@@ -101,9 +36,16 @@ v2.0.0
101
36
  - implement servants for dealing with clumps of functionality, and action commands have access to all servants that were executed before them
102
37
  - ability to break up a big config into chucks, e.g. per command etc. so that it is more modular and easier to read
103
38
  - whether or not action is specified things should not blow up
39
+ - rework ppjson to take advantage of servants and non-block actions and release a new version
104
40
 
105
41
  v2.0.1
106
42
  - lots more logging at different levels for debug purposes
43
+ - more integration specs (more specs for the different types of options)
44
+ - more specs (dsl classes, validator, option_parser, dependency validator, global_pre_parser, auto_options, app)
45
+ - perhaps verbosity should be at the highest level by default and allow toning it down via the setup
46
+ - blog Build Command-Line Apps Like a Pro Using Ruby and Escort
47
+ - pull the terminal formatting stuff into separate gem
48
+ - pull nested exception stuff into separate gem
107
49
 
108
50
 
109
51
 
@@ -151,6 +93,7 @@ BUCKET
151
93
  - json configuration should support having environment configs in multiple files
152
94
  - blog the crap out of all aspects of how to use it, how it is constructed, some fancy things you can do with it etc.
153
95
  - ability to ask for user input for a command (e.g. for passwords, this can possibly be done via validations)
96
+ - do a homebrew config for ppjson so that it can easily be installed using brew
154
97
 
155
98
  - blog about what makes a good command line app (this and the one below are possibly one post)
156
99
  - blog about how to use escort and why the other libraries possibly fall short
@@ -163,6 +106,7 @@ BUCKET
163
106
  - blog about nested exceptions and how to make them nice in your app, also metion exceptional ruby book as well as nestegg gem
164
107
  - blog about dependencies with bundler, the spermy operator and what version will be chosen
165
108
  - blog about ppjson and how to use it
109
+ - reply to a bunch of stackoverflow posts about pretty printing json on the command-line
166
110
 
167
111
  - improve the terminal formatter, allowing wrapping text to anywhere, and tabular like output without an actual table, allowing configuring terminal of any size not just 80, spin it off a little separate project, with an example of how to possibly build a menu in it or something DONE
168
112
  - BUG the help formatting is still not quite right as far as respecting the char limits and wrapping properly when doing tabular output!!!! DONE
@@ -310,3 +254,55 @@ v0.2.0
310
254
  - integration test all the permutations of dependency specification with error and success cases etc DONE
311
255
  - create a shortcut for dependency specification on the opt method options hash itself DONE
312
256
  - fix up example for basic app with dependencies for options DONE
257
+
258
+ v0.3.0
259
+ - tag and release DONE
260
+ - up the version to 0.3.0 DONE
261
+ - test the base command for actions well DONE
262
+ - BUG parent_options when parent of command is global context doesn't seem to work??? DONE
263
+ - integration test for commands DONE
264
+ - integration test for sub-commands DONE
265
+ - readme a basic app with config file, integration test (don't worry about explaining all the helper stuff that gets created) DONE
266
+ - test the configuration loader DONE
267
+ - test the descend to home locator DONE
268
+ - test the configuration merge tool DONE
269
+ - test the configuration generator DONE
270
+ - test all the locators (descend, specfic dir, current script dir, chaining) DONE
271
+ - we should always be using the chaining locator, with more or less sub locators depending on setup DONE
272
+ - create other locators (dir of currently executing script locator, i.e. not the working directory, specified dir locator) DONE
273
+ - create a chaining locator so we can put all our locators together DONE
274
+ - test the configuration reader DONE
275
+ - test the configuration writer DONE
276
+ - a basic app example with all the trimmings DONE
277
+ - app with config file example DONE
278
+ - readme implementing and action for a basic app DONE
279
+ - rejig for betterness the validations help outputs DONE
280
+ - test the string grid DONE
281
+ - start using the new stream output formatter DONE
282
+ - refactor terminal formatter and test it DONE
283
+ - finish testing the output formatter DONE
284
+ - get rid of shell command executor new shell stuff (doesn't work in Jruby and not really needed anyway) DONE
285
+ - extract all the dsl command stuff into a helper module so that global and command can be handled by the same code DONE
286
+
287
+ v0.4.0
288
+ - a few more integration tests (test that basic app automatically gets help and version and that they are correct) DONE
289
+ - have a think about how to make the integration tests a bit more robust, so that failures don't get swallowed (test for specific exit codes instead of non-zero exit code), fix the existing integration tests DONE
290
+ - clean up all the extraneous branches DONE
291
+ - in trollop when errors are raised they should be wrapped as escort errors and propagate rather than being caught by trollop itself DONE
292
+ - rework the examples again to show of some/most of the features (along the lines of the integration tests and readme) DONE
293
+ - errors coming straigh out of configuration should still be caught by error handlers to only display stack trace when needed (refactor app create method) DONE
294
+ - readme for a basic app with conflicting options DONE
295
+ - readme for a basic app with dependent options DONE
296
+ - integration test all the config file helper stuff DONE
297
+ - fix ppjson so that dependency suport feature is actually used DONE
298
+ - delete the stuff from the attic once it is no longer needed DONE
299
+ - readme a sub command app with options, validations, description, summary, require arguments and config file, integration tests, example DONE
300
+ - readme for requires arguments overriding and inheritance DONE
301
+ - readme explain all the helper stuff that automatically gets created with config file support DONE
302
+ - get the blog updated with a new theme DONE
303
+ - put a new subscriber count widget on blog DONE
304
+ - the config auto option should not be included in the config file, same with other auto options??? N/A
305
+ - add a section to readme for command line tools built with escort (e.g. ppjson) DONE
306
+ - rework the integration specs and matchers so there are less moving parts (perhaps push some stuff down into a base class etc.) DONE
307
+ - rewrite the help formatter to be a bit easier to understand (more like man output for output) DONE
308
+ - add depends support to dsl DONE
@@ -12,6 +12,8 @@ Gem::Specification.new do |gem|
12
12
  gem.description = %q{Writing even complex command-line apps should be quick, easy and fun. Escort takes the excellent Trollop option parser and adds a whole bunch of awesome features to produce a library you will always want to turn to when a 'quick script' is in order.}
13
13
  gem.homepage = "https://github.com/skorks/escort"
14
14
 
15
+ gem.add_runtime_dependency('nesty')
16
+
15
17
  gem.add_development_dependency('rspec')
16
18
  gem.add_development_dependency('fakefs')
17
19
  gem.add_development_dependency('rake')
@@ -1,54 +1,73 @@
1
- require 'escort/version'
2
- require 'escort/trollop'
3
- require 'escort/utils'
4
- require 'escort/arguments'
5
- require 'escort/logger'
1
+ autoload :Nesty, "nesty"
6
2
 
7
- require 'escort/error/error'
3
+ module Escort
4
+ autoload :VERSION, "escort/version"
5
+ autoload :Trollop, "escort/trollop"
6
+ autoload :Utils, "escort/utils"
7
+ autoload :Arguments, "escort/arguments"
8
+ autoload :Logger, "escort/logger"
9
+ autoload :SetupAccessor, "escort/setup_accessor"
10
+ autoload :OptionDependencyValidator, "escort/option_dependency_validator"
11
+ autoload :Validator, "escort/validator"
12
+ autoload :AutoOptions, "escort/auto_options"
13
+ autoload :GlobalPreParser, "escort/global_pre_parser"
14
+ autoload :OptionParser, "escort/option_parser"
15
+ autoload :App, "escort/app"
8
16
 
9
- require 'escort/formatter/option'
10
- require 'escort/formatter/options'
11
- require 'escort/formatter/command'
12
- require 'escort/formatter/commands'
13
- require 'escort/formatter/global_command'
14
- require 'escort/formatter/shell_command_executor'
15
- require 'escort/formatter/terminal'
16
- require 'escort/formatter/string_splitter'
17
- require 'escort/formatter/cursor_position'
18
- require 'escort/formatter/stream_output_formatter'
19
- require 'escort/formatter/string_grid'
20
- require 'escort/formatter/default_help_formatter'
17
+ autoload :Error, "escort/error/error"
18
+ autoload :BaseError, "escort/error/error"
19
+ autoload :UserError, "escort/error/error"
20
+ autoload :InternalError, "escort/error/error"
21
+ autoload :ClientError, "escort/error/error"
22
+ autoload :TransientError, "escort/error/error"
21
23
 
22
- require 'escort/setup/dsl/options'
23
- require 'escort/setup/dsl/action'
24
- require 'escort/setup/dsl/command'
25
- require 'escort/setup/dsl/config_file'
26
- require 'escort/setup/dsl/global'
24
+ module Formatter
25
+ autoload :Option, "escort/formatter/option"
26
+ autoload :Options, "escort/formatter/options"
27
+ autoload :Command, "escort/formatter/command"
28
+ autoload :Commands, "escort/formatter/commands"
29
+ autoload :GlobalCommand, "escort/formatter/global_command"
30
+ autoload :ShellCommandExecutor, "escort/formatter/shell_command_executor"
31
+ autoload :Terminal, "escort/formatter/terminal"
32
+ autoload :StringSplitter, "escort/formatter/string_splitter"
33
+ autoload :CursorPosition, "escort/formatter/cursor_position"
34
+ autoload :StreamOutputFormatter, "escort/formatter/stream_output_formatter"
35
+ autoload :StringGrid, "escort/formatter/string_grid"
36
+ autoload :DefaultHelpFormatter, "escort/formatter/default_help_formatter"
37
+ end
27
38
 
28
- require 'escort/setup/configuration/locator/base'
29
- require 'escort/setup/configuration/locator/descending_to_home'
30
- require 'escort/setup/configuration/locator/executing_script_directory'
31
- require 'escort/setup/configuration/locator/specified_directory'
32
- require 'escort/setup/configuration/locator/chaining'
33
- require 'escort/setup/configuration/merge_tool'
34
- require 'escort/setup/configuration/instance'
35
- require 'escort/setup/configuration/reader'
36
- require 'escort/setup/configuration/writer'
37
- require 'escort/setup/configuration/generator'
38
- require 'escort/setup/configuration/loader'
39
+ module Setup
40
+ module Dsl
41
+ autoload :Options, "escort/setup/dsl/options"
42
+ autoload :Action, "escort/setup/dsl/action"
43
+ autoload :Command, "escort/setup/dsl/command"
44
+ autoload :ConfigFile, "escort/setup/dsl/config_file"
45
+ autoload :Global, "escort/setup/dsl/global"
46
+ end
39
47
 
40
- require 'escort/setup_accessor'
48
+ module Configuration
49
+ module Locator
50
+ autoload :Base, "escort/setup/configuration/locator/base"
51
+ autoload :DescendingToHome, "escort/setup/configuration/locator/descending_to_home"
52
+ autoload :ExecutingScriptDirectory, "escort/setup/configuration/locator/executing_script_directory"
53
+ autoload :SpecifiedDirectory, "escort/setup/configuration/locator/specified_directory"
54
+ autoload :Chaining, "escort/setup/configuration/locator/chaining"
55
+ end
41
56
 
42
- require 'escort/option_dependency_validator'
43
- require 'escort/validator'
44
- require 'escort/auto_options'
45
- require 'escort/global_pre_parser'
46
- require 'escort/option_parser'
57
+ autoload :MergeTool, "escort/setup/configuration/merge_tool"
58
+ autoload :Instance, "escort/setup/configuration/instance"
59
+ autoload :Reader, "escort/setup/configuration/reader"
60
+ autoload :Writer, "escort/setup/configuration/writer"
61
+ autoload :Generator, "escort/setup/configuration/generator"
62
+ autoload :Loader, "escort/setup/configuration/loader"
63
+ end
64
+ end
47
65
 
48
- require 'escort/action_command/base'
49
- require 'escort/action_command/escort_utility_command'
50
-
51
- require 'escort/app'
66
+ module ActionCommand
67
+ autoload :Base, "escort/action_command/base"
68
+ autoload :EscortUtilityCommand, "escort/action_command/escort_utility_command"
69
+ end
70
+ end
52
71
 
53
72
  at_exit do
54
73
  Escort::Logger.close
@@ -11,25 +11,8 @@ module Escort
11
11
  #all our exceptions will supported nesting other exceptions
12
12
  #also all our exception will be a kind_of? Escort::Error
13
13
  class BaseError < StandardError
14
+ include Nesty::NestedError
14
15
  include Error
15
- attr_reader :original
16
-
17
- def initialize(msg, original=$!)
18
- super(msg)
19
- @original = original
20
- end
21
-
22
- def set_backtrace(bt)
23
- if original
24
- original.backtrace.reverse.each do |line|
25
- bt.last == line ? bt.pop : break
26
- end
27
- original_first = original.backtrace.shift
28
- bt.concat ["#{original_first}: #{original.message}"]
29
- bt.concat original.backtrace
30
- end
31
- super(bt)
32
- end
33
16
  end
34
17
 
35
18
  #user did something invalid
@@ -112,11 +112,6 @@ module Escort
112
112
 
113
113
  def add_global_command(name, options = {}, &block)
114
114
  global_instance.command(name, options, &block)
115
-
116
- #with_context([]) do |current_context|
117
- #commands = fetch_instance_variable_from(current_context, :commands)
118
- #options_object.opt name, desc, options
119
- #end
120
115
  end
121
116
 
122
117
  private
@@ -1,3 +1,3 @@
1
1
  module Escort
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -79,4 +79,48 @@ describe "Escort basic app with config file defined", :integration => true do
79
79
  it("should not have created a config file in default location") { File.should_not exist path }
80
80
  end
81
81
  end
82
+
83
+ context "when config file specified" do
84
+ let(:autocreate) {false}
85
+
86
+ before do
87
+ FileUtils.mkdir_p(File.dirname path)
88
+ File.open(path, 'w') {|f| f.write(JSON.pretty_generate({:global => {:commands => {}, :options => {:option1 => 'hello'}}, :user => {}})) }
89
+
90
+ begin
91
+ subject
92
+ rescue SystemExit => e
93
+ end
94
+ end
95
+
96
+ context "--config global option should exist" do
97
+ let(:option_string) { "--config=#{path}" }
98
+ it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
99
+ end
100
+
101
+ context "escort command should exist" do
102
+ let(:option_string) { "escort -h" }
103
+ it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
104
+
105
+ context "--create-config option for escort command should exist" do
106
+ let(:option_string) { "escort --create-config=#{path}" }
107
+ it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
108
+ end
109
+
110
+ context "--create-default-config option for escort command should exist" do
111
+ let(:option_string) { "escort --create-default-config" }
112
+ it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
113
+ end
114
+
115
+ context "--update-config option for escort command should exist" do
116
+ let(:option_string) { "escort --update-config=#{path}" }
117
+ it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
118
+ end
119
+
120
+ context "--update-default-config option for escort command should exist" do
121
+ let(:option_string) { "escort --update-default-config" }
122
+ it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
123
+ end
124
+ end
125
+ end
82
126
  end
@@ -20,4 +20,19 @@ describe "Escort basic app with no options defined", :integration => true do
20
20
  it("exit code should be 0") { expect{ subject }.to exit_with_code(0) }
21
21
  it("should execute the global action") { expect{subject}.to execute_action_for_command(result, :global) }
22
22
  end
23
+
24
+ context "gets --help option automatically" do
25
+ let(:option_string) { "--help" }
26
+ it("exit code should be 0") { expect{ subject }.to exit_with_code(0) }
27
+ end
28
+
29
+ context "gets --verbosity option automatically" do
30
+ let(:option_string) { "--verbosity=DEBUG" }
31
+ it("exit code should be 0") { expect{ subject }.to exit_with_code(0) }
32
+ end
33
+
34
+ context "gets --error-output-format option automatically" do
35
+ let(:option_string) { "--error-output-format=advanced" }
36
+ it("exit code should be 0") { expect{ subject }.to exit_with_code(0) }
37
+ end
23
38
  end
@@ -1,3 +1,5 @@
1
+ require 'readline'
2
+
1
3
  describe "Escort basic app that requires arguments", :integration => true do
2
4
  subject { Escort::App.create(option_string, &app_configuration) }
3
5
 
@@ -4,7 +4,15 @@ describe Escort::SetupAccessor do
4
4
  let(:global_app_configuration) do
5
5
  Escort::Setup::Dsl::Global.new do |app|
6
6
  app.options do |opts|
7
- opts.opt :option1, "option1", :short => :none, :long => '--option1', :type => :string
7
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
8
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
9
+ opts.opt :int_option, "Int option", :short => '-i', :long => '--int-option', :type => :int
10
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean, :default => true
11
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
12
+
13
+ opts.conflict :flag1, :flag2
14
+ opts.dependency :option1, :on => :flag1
15
+ opts.validate(:int_option, "must be greater than 10") { |option| option > 10 }
8
16
  end
9
17
 
10
18
  app.action do |options, arguments|
@@ -13,31 +21,206 @@ describe Escort::SetupAccessor do
13
21
  end
14
22
 
15
23
  let(:command_app_configuration) do
24
+ Escort::Setup::Dsl::Global.new do |app|
25
+ app.options do |opts|
26
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
27
+ end
28
+
29
+ app.command :command1 do |command|
30
+ command.options do |opts|
31
+ opts.opt :option1, "Option1 for command1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1 command 1"
32
+ opts.opt :flag_for_command1, "Flag for command 1", :short => :none, :long => '--flag-for-command1', :type => :boolean
33
+
34
+ opts.dependency :option1, :on => :flag_for_command1
35
+ end
36
+
37
+ command.action do |options, arguments|
38
+ end
39
+ end
40
+
41
+ app.command :command2, :aliases => :c2 do |command|
42
+ command.options do |opts|
43
+ opts.opt :optionb, "Optionb", :short => :none, :long => '--optionb', :type => :string, :multi => true
44
+ opts.opt :float_option, "Float option", :short => '-d', :long => '--float-option', :type => :float
45
+
46
+ opts.conflict :optionb, :float_option
47
+ opts.validate(:float_option, "must be less than 5") { |option| option < 5 }
48
+ end
49
+
50
+ command.action do |options, arguments|
51
+ end
52
+ end
53
+
54
+ app.action do |options, arguments|
55
+ end
56
+ end
16
57
  end
17
58
 
18
59
  let(:sub_command_app_configuration) do
60
+ Escort::Setup::Dsl::Global.new do |app|
61
+ app.options do |opts|
62
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
63
+ end
64
+
65
+ app.command :command2, :aliases => :c2 do |command|
66
+ command.options do |opts|
67
+ opts.opt :optionb, "Optionb", :short => :none, :long => '--optionb', :type => :string, :multi => true
68
+ opts.opt :float_option, "Float option", :short => '-d', :long => '--float-option', :type => :float
69
+
70
+ opts.conflict :optionb, :float_option
71
+ opts.validate(:float_option, "must be less than 5") { |option| option < 5 }
72
+ end
73
+
74
+ command.command :sub_command1 do |command|
75
+ command.options do |opts|
76
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
77
+ end
78
+
79
+ command.action do |options, arguments|
80
+ end
81
+ end
82
+
83
+ command.command :sub_command2 do |command|
84
+ command.options do |opts|
85
+ opts.opt :sub_option1, "Sub option1", :short => '-s', :long => '--sub-option1', :type => :string
86
+ opts.validate(:sub_option1, "must be 'x' or 'y'") { |option| ['x', 'y'].include? option }
87
+ end
88
+
89
+ command.action do |options, arguments|
90
+ end
91
+ end
92
+
93
+ command.action do |options, arguments|
94
+ end
95
+ end
96
+
97
+ app.action do |options, arguments|
98
+ end
99
+ end
19
100
  end
20
101
 
21
- #context is nil
22
- #no context supplied at all
23
- #context is not an array
24
102
  describe '#options_for' do
25
- subject {setup.options_for(context)}
103
+ let(:options) {setup.options_for(context)}
26
104
 
27
105
  context "when app has no sub commands" do
28
106
  let(:app_configuration) {global_app_configuration}
29
107
 
30
108
  context "and context is global" do
31
109
  let(:context) { [] }
32
- it(":option1 should be present") {subject[:option1].should_not be_nil}
110
+ it(":option1 should be present") {options[:option1].should_not be_nil}
33
111
  end
34
112
 
35
113
  context "and context is an unknown command" do
36
114
  let(:context) { ['hello'] }
37
- it("should not raise an exception") { expect{subject}.to_not raise_error }
38
- it("result should be a hash") { subject.class.should == Hash }
39
- it("result should be empty") { subject.should be_empty }
115
+ it("should not raise an exception") { expect{options}.to_not raise_error }
116
+ it("result should be a hash") { options.class.should == Hash }
117
+ it("result should be empty") { options.should be_empty }
118
+ end
119
+
120
+ context "and no context passed in at all" do
121
+ let(:options) {setup.options_for}
122
+ it(":option1 should be present") {options[:option1].should_not be_nil}
123
+ end
124
+
125
+ context "and context is nil" do
126
+ let(:context) { nil }
127
+ it(":option1 should be present") {options[:option1].should_not be_nil}
128
+ end
129
+
130
+ context "and context is not an array" do
131
+ let(:context) { 'hello' }
132
+ it("should not raise an exception") { expect{options}.to_not raise_error }
40
133
  end
41
134
  end
135
+
136
+ context "when app has one level of sub commands" do
137
+ let(:app_configuration) {command_app_configuration}
138
+
139
+ context "and context is a known command" do
140
+ let(:context) { ['command1'] }
141
+ it("result should be a hash") { options.class.should == Hash }
142
+ it("result should not be empty") { options.should_not be_empty }
143
+ it(":option1 should be present") {options[:option1].should_not be_nil}
144
+ end
145
+ end
146
+
147
+ context "when app has multiple levels of sub commands" do
148
+ let(:app_configuration) {sub_command_app_configuration}
149
+
150
+ context "and context is a known sub command" do
151
+ let(:context) { ['command2', 'sub_command2'] }
152
+ it("result should be a hash") { options.class.should == Hash }
153
+ it("result should not be empty") { options.should_not be_empty }
154
+ it(":sub_option1 should be present") {options[:sub_option1].should_not be_nil}
155
+ end
156
+ end
157
+ end
158
+
159
+ describe '#conflicting_options_for' do
160
+ #TODO implement
161
+ end
162
+
163
+ describe '#validations_for' do
164
+ #TODO implement
165
+ end
166
+
167
+ describe '#dependencies_for' do
168
+ #TODO implement
169
+ end
170
+
171
+ describe '#command_names_for' do
172
+ #TODO implement
173
+ end
174
+
175
+ describe '#canonical_command_names_for' do
176
+ #TODO implement
177
+ end
178
+
179
+ describe '#action_for' do
180
+ #TODO implement
181
+ end
182
+
183
+ describe '#arguments_required_for' do
184
+ #TODO implement
185
+ end
186
+
187
+ describe '#has_config_file?' do
188
+ #TODO implement
189
+ end
190
+
191
+ describe '#config_file_autocreatable?' do
192
+ #TODO implement
193
+ end
194
+
195
+ describe '#config_file' do
196
+ #TODO implement
197
+ end
198
+
199
+ describe '#summary_for' do
200
+ #TODO implement
201
+ end
202
+
203
+ describe '#description_for' do
204
+ #TODO implement
205
+ end
206
+
207
+ describe '#command_description_for' do
208
+ #TODO implement
209
+ end
210
+
211
+ describe '#command_summary_for' do
212
+ #TODO implement
213
+ end
214
+
215
+ describe '#command_aliases_for' do
216
+ #TODO implement
217
+ end
218
+
219
+ describe '#add_global_option' do
220
+ #TODO implement
221
+ end
222
+
223
+ describe '#add_global_command' do
224
+ #TODO implement
42
225
  end
43
226
  end
@@ -5,7 +5,7 @@ shared_context "integration test setup", :integration => true do
5
5
  empty_argv
6
6
  #$stderr = StringIO.new
7
7
  #$stdout = StringIO.new
8
- $stdin = StringIO.new
8
+ #$stdin = StringIO.new
9
9
  end
10
10
 
11
11
  after do
metadata CHANGED
@@ -1,69 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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-13 00:00:00.000000000 Z
11
+ date: 2013-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nesty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ! '>='
31
+ - - '>='
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ! '>='
38
+ - - '>='
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: fakefs
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ! '>='
45
+ - - '>='
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ! '>='
59
+ - - '>='
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ! '>='
66
+ - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: travis-lint
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ! '>='
73
+ - - '>='
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ! '>='
80
+ - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description: Writing even complex command-line apps should be quick, easy and fun.
@@ -79,7 +93,7 @@ files:
79
93
  - .gitignore
80
94
  - .irbrc
81
95
  - .rspec
82
- - .rvmrc
96
+ - .ruby-version
83
97
  - .travis.yml
84
98
  - Gemfile
85
99
  - LICENSE.txt
@@ -194,12 +208,12 @@ require_paths:
194
208
  - lib
195
209
  required_ruby_version: !ruby/object:Gem::Requirement
196
210
  requirements:
197
- - - ! '>='
211
+ - - '>='
198
212
  - !ruby/object:Gem::Version
199
213
  version: '0'
200
214
  required_rubygems_version: !ruby/object:Gem::Requirement
201
215
  requirements:
202
- - - ! '>='
216
+ - - '>='
203
217
  - !ruby/object:Gem::Version
204
218
  version: '0'
205
219
  requirements: []
data/.rvmrc DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- failed=1
4
- gemset=escort
5
- rubies="ruby-1.9.3-p362 ruby-1.9.3-p194 ruby-1.9.2-p290 "
6
-
7
- for ruby in $rubies; do
8
- rvm use $ruby@$gemset --create 1>/dev/null 2>&1
9
- if [ $? == 0 ]; then
10
- echo
11
- echo ">>" rvm is using $ruby@$gemset
12
- echo
13
- failed=0
14
- break
15
- fi
16
- done
17
-
18
- if [ $failed == 1 ]; then
19
- echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
- echo cannot find a ruby runtime in the set: $rubies, please install one
21
- echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
- fi