convoy 1.0.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.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.irbrc +3 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +8 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +22 -0
  9. data/README.md +705 -0
  10. data/Rakefile +1 -0
  11. data/convoy.gemspec +24 -0
  12. data/examples/.my_apprc +24 -0
  13. data/examples/basic +10 -0
  14. data/examples/basic_config_file +16 -0
  15. data/examples/basic_conflicts +17 -0
  16. data/examples/basic_depends_on +25 -0
  17. data/examples/basic_flags +15 -0
  18. data/examples/basic_options +14 -0
  19. data/examples/basic_options_multi +15 -0
  20. data/examples/basic_require_arguments +17 -0
  21. data/examples/basic_texts +21 -0
  22. data/examples/basic_validations +21 -0
  23. data/examples/basic_with_everything +30 -0
  24. data/examples/commands/example_command.rb +13 -0
  25. data/examples/suite_complex +65 -0
  26. data/examples/suite_simple +19 -0
  27. data/examples/suite_with_sub_commands +94 -0
  28. data/lib/convoy.rb +83 -0
  29. data/lib/convoy/action_command/base.rb +85 -0
  30. data/lib/convoy/action_command/escort_utility_command.rb +53 -0
  31. data/lib/convoy/app.rb +127 -0
  32. data/lib/convoy/arguments.rb +20 -0
  33. data/lib/convoy/auto_options.rb +71 -0
  34. data/lib/convoy/error/error.rb +33 -0
  35. data/lib/convoy/formatter/command.rb +87 -0
  36. data/lib/convoy/formatter/commands.rb +37 -0
  37. data/lib/convoy/formatter/cursor_position.rb +29 -0
  38. data/lib/convoy/formatter/default_help_formatter.rb +117 -0
  39. data/lib/convoy/formatter/global_command.rb +17 -0
  40. data/lib/convoy/formatter/option.rb +152 -0
  41. data/lib/convoy/formatter/options.rb +28 -0
  42. data/lib/convoy/formatter/shell_command_executor.rb +49 -0
  43. data/lib/convoy/formatter/stream_output_formatter.rb +88 -0
  44. data/lib/convoy/formatter/string_grid.rb +108 -0
  45. data/lib/convoy/formatter/string_splitter.rb +50 -0
  46. data/lib/convoy/formatter/terminal.rb +30 -0
  47. data/lib/convoy/global_pre_parser.rb +43 -0
  48. data/lib/convoy/logger.rb +75 -0
  49. data/lib/convoy/option_dependency_validator.rb +82 -0
  50. data/lib/convoy/option_parser.rb +155 -0
  51. data/lib/convoy/setup/configuration/generator.rb +75 -0
  52. data/lib/convoy/setup/configuration/instance.rb +34 -0
  53. data/lib/convoy/setup/configuration/loader.rb +43 -0
  54. data/lib/convoy/setup/configuration/locator/base.rb +19 -0
  55. data/lib/convoy/setup/configuration/locator/chaining.rb +29 -0
  56. data/lib/convoy/setup/configuration/locator/descending_to_home.rb +23 -0
  57. data/lib/convoy/setup/configuration/locator/executing_script_directory.rb +15 -0
  58. data/lib/convoy/setup/configuration/locator/specified_directory.rb +21 -0
  59. data/lib/convoy/setup/configuration/merge_tool.rb +38 -0
  60. data/lib/convoy/setup/configuration/reader.rb +36 -0
  61. data/lib/convoy/setup/configuration/writer.rb +46 -0
  62. data/lib/convoy/setup/dsl/action.rb +17 -0
  63. data/lib/convoy/setup/dsl/command.rb +67 -0
  64. data/lib/convoy/setup/dsl/config_file.rb +13 -0
  65. data/lib/convoy/setup/dsl/global.rb +29 -0
  66. data/lib/convoy/setup/dsl/options.rb +81 -0
  67. data/lib/convoy/setup_accessor.rb +206 -0
  68. data/lib/convoy/trollop.rb +861 -0
  69. data/lib/convoy/utils.rb +21 -0
  70. data/lib/convoy/validator.rb +45 -0
  71. data/spec/integration/basic_config_file_spec.rb +126 -0
  72. data/spec/integration/basic_conflicts_spec.rb +47 -0
  73. data/spec/integration/basic_depends_on_spec.rb +275 -0
  74. data/spec/integration/basic_options_spec.rb +41 -0
  75. data/spec/integration/basic_options_with_multi_spec.rb +30 -0
  76. data/spec/integration/basic_spec.rb +38 -0
  77. data/spec/integration/basic_validations_spec.rb +77 -0
  78. data/spec/integration/basic_with_arguments_spec.rb +35 -0
  79. data/spec/integration/basic_with_text_fields_spec.rb +21 -0
  80. data/spec/integration/suite_simple_spec.rb +45 -0
  81. data/spec/integration/suite_sub_command_spec.rb +51 -0
  82. data/spec/lib/convoy/action_command/base_spec.rb +200 -0
  83. data/spec/lib/convoy/formatter/command_spec.rb +238 -0
  84. data/spec/lib/convoy/formatter/global_command_spec.rb +50 -0
  85. data/spec/lib/convoy/formatter/option_spec.rb +300 -0
  86. data/spec/lib/convoy/formatter/shell_command_executor_spec.rb +59 -0
  87. data/spec/lib/convoy/formatter/stream_output_formatter_spec.rb +214 -0
  88. data/spec/lib/convoy/formatter/string_grid_spec.rb +59 -0
  89. data/spec/lib/convoy/formatter/string_splitter_spec.rb +50 -0
  90. data/spec/lib/convoy/formatter/terminal_spec.rb +19 -0
  91. data/spec/lib/convoy/setup/configuration/generator_spec.rb +101 -0
  92. data/spec/lib/convoy/setup/configuration/loader_spec.rb +79 -0
  93. data/spec/lib/convoy/setup/configuration/locator/chaining_spec.rb +81 -0
  94. data/spec/lib/convoy/setup/configuration/locator/descending_to_home_spec.rb +57 -0
  95. data/spec/lib/convoy/setup/configuration/locator/executing_script_directory_spec.rb +29 -0
  96. data/spec/lib/convoy/setup/configuration/locator/specified_directory_spec.rb +33 -0
  97. data/spec/lib/convoy/setup/configuration/merge_tool_spec.rb +41 -0
  98. data/spec/lib/convoy/setup/configuration/reader_spec.rb +41 -0
  99. data/spec/lib/convoy/setup/configuration/writer_spec.rb +75 -0
  100. data/spec/lib/convoy/setup_accessor_spec.rb +226 -0
  101. data/spec/lib/convoy/utils_spec.rb +30 -0
  102. data/spec/spec_helper.rb +29 -0
  103. data/spec/support/integration_helpers.rb +2 -0
  104. data/spec/support/matchers/execute_action_for_command_matcher.rb +21 -0
  105. data/spec/support/matchers/execute_action_with_arguments_matcher.rb +25 -0
  106. data/spec/support/matchers/execute_action_with_options_matcher.rb +29 -0
  107. data/spec/support/matchers/exit_with_code_matcher.rb +29 -0
  108. data/spec/support/shared_contexts/integration_setup.rb +34 -0
  109. metadata +292 -0
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/convoy.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH << File.expand_path(File.join('..', 'lib'), __FILE__)
2
+
3
+ require 'date'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'convoy'
7
+ s.version = '1.0.0'
8
+ s.date = Date.today.to_s
9
+ s.summary = %q{A library that makes building command line apps in ruby so easy, you'll feel like an expert is guiding you through it}
10
+ s.description = %q{Writing even complex command-line apps should be quick, easy and fun. Convoy 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.}
11
+ s.authors = ['Albert Rannetsperger']
12
+ s.email = 'alb3rtuk@hotmail.com'
13
+ s.homepage = 'http://github.com/alb3rtuk/convoy'
14
+ s.license = 'MIT'
15
+ s.require_paths = ['lib']
16
+ s.files = `git ls-files`.split($/)
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.add_runtime_dependency 'nesty', '~> 1.0', '>= 1.0.2'
19
+ s.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
20
+ s.add_development_dependency 'fakefs', '~> 0.5', '>= 0.5.3'
21
+ s.add_development_dependency 'rake', '~> 10.3', '>= 10.3.2'
22
+ s.add_development_dependency 'travis-lint', '~> 2.0', '>= 2.0.0'
23
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
24
+ end
@@ -0,0 +1,24 @@
1
+ {
2
+ "global": {
3
+ "options": {
4
+ "option1": "option from file",
5
+ "config": null,
6
+ "verbosity": "WARN",
7
+ "error_output_format": "basic"
8
+ },
9
+ "commands": {
10
+ "convoy": {
11
+ "options": {
12
+ "create_config": null,
13
+ "create_default_config": null,
14
+ "update_config": null,
15
+ "update_default_config": null
16
+ },
17
+ "commands": {
18
+ }
19
+ }
20
+ }
21
+ },
22
+ "user": {
23
+ }
24
+ }
data/examples/basic ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.action do |options, arguments|
8
+ Convoy::ExampleCommand.new(options, arguments).execute
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.config_file ".my_apprc", :autocreate => true
8
+
9
+ app.options do |opts|
10
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
11
+ end
12
+
13
+ app.action do |options, arguments|
14
+ Convoy::ExampleCommand.new(options, arguments).execute
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.options do |opts|
8
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
9
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
10
+
11
+ opts.conflict :flag1, :flag2
12
+ end
13
+
14
+ app.action do |options, arguments|
15
+ Convoy::ExampleCommand.new(options, arguments).execute
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.options do |opts|
8
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
9
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean, :default => true
10
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
11
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
12
+ opts.opt :option3, "Option3", :short => :none, :long => '--option3', :type => :string
13
+ opts.opt :option4, "Option4", :short => :none, :long => '--option4', :type => :string
14
+
15
+ opts.dependency :option1, :on => :flag1
16
+ opts.dependency :option2, :on => [:flag1, :option1]
17
+ opts.dependency :option3, :on => {:option1 => 'foo'}
18
+ #opts.dependency :option4, :on => [{:flag1 => false}, :option1] #This will get you into big trouble as it can never be fulfilled
19
+ opts.dependency :option4, :on => [{:flag2 => false}, :option1]
20
+ end
21
+
22
+ app.action do |options, arguments|
23
+ Convoy::ExampleCommand.new(options, arguments).execute
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.options do |opts|
8
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean, :default => true
9
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
10
+ end
11
+
12
+ app.action do |options, arguments|
13
+ Convoy::ExampleCommand.new(options, arguments).execute
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.options do |opts|
8
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
9
+ end
10
+
11
+ app.action do |options, arguments|
12
+ Convoy::ExampleCommand.new(options, arguments).execute
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.options do |opts|
8
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
9
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
10
+ end
11
+
12
+ app.action do |options, arguments|
13
+ Convoy::ExampleCommand.new(options, arguments).execute
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.requires_arguments
8
+
9
+ app.options do |opts|
10
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
11
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
12
+ end
13
+
14
+ app.action do |options, arguments|
15
+ Convoy::ExampleCommand.new(options, arguments).execute
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.version "0.1.1"
8
+ app.summary "Summary 1"
9
+ app.description "Description 1"
10
+
11
+ app.requires_arguments
12
+
13
+ app.options do |opts|
14
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
15
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
16
+ end
17
+
18
+ app.action do |options, arguments|
19
+ Convoy::ExampleCommand.new(options, arguments).execute
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.options do |opts|
8
+ opts.opt :option1, "Option 1", :short => '-o', :long => '--option1', :type => :string
9
+ opts.opt :int1, "Int 1", :short => '-i', :long => '--int1', :type => :int
10
+ opts.opt :option2, "Option 2", :short => :none, :long => '--option2', :type => :string
11
+
12
+ opts.validate(:option1, "must be either 'foo' or 'bar'") { |option| ["foo", "bar"].include?(option) }
13
+ opts.validate(:int1, "must be between 10 and 20 exclusive") { |option| option > 10 && option < 20 }
14
+ opts.validate(:option2, "must be two words") { |option| option =~ /\w\s\w/ }
15
+ opts.validate(:option2, "must be at least 20 characters long") { |option| option.length >= 20 }
16
+ end
17
+
18
+ app.action do |options, arguments|
19
+ Convoy::ExampleCommand.new(options, arguments).execute
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.version "0.1.1"
8
+ app.summary "Summary 1"
9
+ app.description "Description 1"
10
+
11
+ app.config_file ".my_apprc", :autocreate => false
12
+
13
+ app.requires_arguments
14
+
15
+ app.options do |opts|
16
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
17
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
18
+ opts.opt :int_option, "Int option", :short => '-i', :long => '--int-option', :type => :int
19
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean, :default => true
20
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
21
+
22
+ opts.conflict :flag1, :flag2
23
+ opts.dependency :option1, :on => :flag1
24
+ opts.validate(:int_option, "must be greater than 10") { |option| option > 10 }
25
+ end
26
+
27
+ app.action do |options, arguments|
28
+ Convoy::ExampleCommand.new(options, arguments).execute
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Convoy
2
+ class ExampleCommand < ::Convoy::ActionCommand::Base
3
+ def execute
4
+ Convoy::Logger.output.puts "Command: #{command_name}"
5
+ Convoy::Logger.output.puts "Options: #{options}"
6
+ Convoy::Logger.output.puts "Command options: #{command_options}"
7
+ Convoy::Logger.output.puts "Arguments: #{arguments}"
8
+ if config
9
+ Convoy::Logger.output.puts "User config: #{config}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.version "0.1.1"
8
+ app.summary "Summary 1"
9
+ app.description "Description 1"
10
+
11
+ app.config_file ".my_apprc", :autocreate => false
12
+
13
+ app.requires_arguments
14
+
15
+ app.options do |opts|
16
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
17
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
18
+ opts.opt :int_option, "Int option", :short => '-i', :long => '--int-option', :type => :int
19
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean, :default => true
20
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
21
+
22
+ opts.conflict :flag1, :flag2
23
+ opts.dependency :option1, :on => :flag1
24
+ opts.validate(:int_option, "must be greater than 10") { |option| option > 10 }
25
+ end
26
+
27
+ app.command :command1 do |command|
28
+ command.summary "Command summary 1"
29
+ command.description "Command description 1"
30
+
31
+ command.options do |opts|
32
+ opts.opt :option1, "Option1 for command1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1 command 1"
33
+ opts.opt :flag_for_command1, "Flag for command 1", :short => :none, :long => '--flag-for-command1', :type => :boolean
34
+
35
+ opts.dependency :option1, :on => :flag_for_command1
36
+ end
37
+
38
+ command.action do |options, arguments|
39
+ Convoy::ExampleCommand.new(options, arguments).execute
40
+ end
41
+ end
42
+
43
+ app.command :command2, :aliases => :c2 do |command|
44
+ command.summary "Command summary 2"
45
+ command.description "Command description 2"
46
+
47
+ command.requires_arguments false
48
+
49
+ command.options do |opts|
50
+ opts.opt :optionb, "Optionb", :short => :none, :long => '--optionb', :type => :string, :multi => true
51
+ opts.opt :float_option, "Float option", :short => '-d', :long => '--float-option', :type => :float
52
+
53
+ opts.conflict :optionb, :float_option
54
+ opts.validate(:float_option, "must be less than 5") { |option| option < 5 }
55
+ end
56
+
57
+ command.action do |options, arguments|
58
+ Convoy::ExampleCommand.new(options, arguments).execute
59
+ end
60
+ end
61
+
62
+ app.action do |options, arguments|
63
+ Convoy::ExampleCommand.new(options, arguments).execute
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.command :command1, :aliases => [:c1, :com1] do |command|
8
+ command.summary "Command summary 1"
9
+ command.description "Command description 1"
10
+
11
+ command.action do |options, arguments|
12
+ Convoy::ExampleCommand.new(options, arguments).execute
13
+ end
14
+ end
15
+
16
+ app.action do |options, arguments|
17
+ Convoy::ExampleCommand.new(options, arguments).execute
18
+ end
19
+ end
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.expand_path(__FILE__), "..", "..", "lib", "convoy"))
4
+ require File.join(File.expand_path(__FILE__), "..", "commands", "example_command")
5
+
6
+ Convoy::App.create do |app|
7
+ app.version "0.1.1"
8
+ app.summary "Summary 1"
9
+ app.description "Description 1"
10
+
11
+ app.config_file ".my_apprc", :autocreate => false
12
+
13
+ app.requires_arguments
14
+
15
+ app.options do |opts|
16
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
17
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
18
+ opts.opt :int_option, "Int option", :short => '-i', :long => '--int-option', :type => :int
19
+ opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean, :default => true
20
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
21
+
22
+ opts.conflict :flag1, :flag2
23
+ opts.dependency :option1, :on => :flag1
24
+ opts.validate(:int_option, "must be greater than 10") { |option| option > 10 }
25
+ end
26
+
27
+ app.command :command1 do |command|
28
+ command.summary "Command summary 1"
29
+ command.description "Command description 1"
30
+
31
+ command.options do |opts|
32
+ opts.opt :option1, "Option1 for command1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1 command 1"
33
+ opts.opt :flag_for_command1, "Flag for command 1", :short => :none, :long => '--flag-for-command1', :type => :boolean
34
+
35
+ opts.dependency :option1, :on => :flag_for_command1
36
+ end
37
+
38
+ command.action do |options, arguments|
39
+ Convoy::ExampleCommand.new(options, arguments).execute
40
+ end
41
+ end
42
+
43
+ app.command :command2, :aliases => :c2 do |command|
44
+ command.summary "Command summary 2"
45
+ command.description "Command description 2"
46
+
47
+ command.requires_arguments false
48
+
49
+ command.options do |opts|
50
+ opts.opt :optionb, "Optionb", :short => :none, :long => '--optionb', :type => :string, :multi => true
51
+ opts.opt :float_option, "Float option", :short => '-d', :long => '--float-option', :type => :float
52
+
53
+ opts.conflict :optionb, :float_option
54
+ opts.validate(:float_option, "must be less than 5") { |option| option < 5 }
55
+ end
56
+
57
+ command.command :sub_command1 do |command|
58
+ command.summary "Sub command summary 1"
59
+ command.description "Sub command description 1"
60
+
61
+ command.requires_arguments
62
+
63
+ command.options do |opts|
64
+ opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean
65
+ end
66
+
67
+ command.action do |options, arguments|
68
+ Convoy::ExampleCommand.new(options, arguments).execute
69
+ end
70
+ end
71
+
72
+ command.command :sub_command2 do |command|
73
+ command.summary "Sub command summary 2"
74
+ command.description "Sub command description 2"
75
+
76
+ command.options do |opts|
77
+ opts.opt :sub_option1, "Sub option1", :short => '-s', :long => '--sub-option1', :type => :string
78
+ opts.validate(:sub_option1, "must be 'x' or 'y'") { |option| ['x', 'y'].include? option }
79
+ end
80
+
81
+ command.action do |options, arguments|
82
+ Convoy::ExampleCommand.new(options, arguments).execute
83
+ end
84
+ end
85
+
86
+ command.action do |options, arguments|
87
+ Convoy::ExampleCommand.new(options, arguments).execute
88
+ end
89
+ end
90
+
91
+ app.action do |options, arguments|
92
+ Convoy::ExampleCommand.new(options, arguments).execute
93
+ end
94
+ end