eac_cli 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e2305c2b18d413d495a33e51960457e7dac373738a7d27dff2827467c473ff1
4
- data.tar.gz: 6a898a395163b7ba890ddb6bf6b33401dc2b35b644901a79c7c413db11237adc
3
+ metadata.gz: 22db6b0edb02623b574dc9545e67dc42ac19d35ec6da4010b0c463c886aacfe3
4
+ data.tar.gz: 8164b097784d2d63d805de366c830a0313bdd244a4656326ace4c01faa17ac52
5
5
  SHA512:
6
- metadata.gz: 5c77641706241d55d18e46c00561679f079edbdec72049b13812f470034bf6b5c1164f07cf9dadee1649194878a22fbd4679065922018e971fa369f279d746d8
7
- data.tar.gz: 184c4741948f5014aeac1704745f11accd99f3c2c514c2df2d96fd9f8458dab6aa0de993b9a4b8b79b3caf52d4ab9de5ddbb367219095c5cd90a2206db97d25f
6
+ metadata.gz: d013970f6550f09e9ff0411326ee6b014b4685c33b7f96ff1c3db2321521114b33746e87bac97fa4f96c779b4efff8f1d420c88b93319998a08c7c10d288342f
7
+ data.tar.gz: 1d3c695a9c107e69a54062e5e2fa4cd6ebaa9b9e935a6902e185078eb2ff0fbdffb7c6d83e252d892702ec2b6a8c305a55269f1e05d67af0daeadabe9e8fa2bb
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/argument_option'
4
+ require 'eac_cli/definition/boolean_option'
5
+ require 'eac_cli/definition/positional_argument'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module EacCli
9
+ class Definition
10
+ require_sub __FILE__
11
+ attr_accessor :description
12
+ attr_accessor :options_argument
13
+
14
+ def initialize
15
+ self.description = '-- NO DESCRIPTION SET --'
16
+ self.options_argument = true
17
+ end
18
+
19
+ def alt(&block)
20
+ r = ::EacCli::Definition.new
21
+ r.instance_eval(&block)
22
+ alternatives << r
23
+ r
24
+ end
25
+
26
+ def alternatives
27
+ @alternatives ||= []
28
+ end
29
+
30
+ def arg_opt(short, long, description, option_options = {})
31
+ options << ::EacCli::Definition::ArgumentOption.new(
32
+ short, long, description, option_options
33
+ )
34
+ end
35
+
36
+ def bool_opt(short, long, description, option_options = {})
37
+ options << ::EacCli::Definition::BooleanOption.new(short, long, description, option_options)
38
+ end
39
+
40
+ def desc(description)
41
+ self.description = description
42
+ end
43
+
44
+ def options_arg(options_argument)
45
+ self.options_argument = options_argument
46
+ end
47
+
48
+ def options
49
+ @options ||= []
50
+ end
51
+
52
+ def pos_arg(name, arg_options = {})
53
+ positional << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
54
+ end
55
+
56
+ def positional
57
+ @positional ||= []
58
+ end
59
+
60
+ def subcommands
61
+ positional << ::EacCli::Definition::PositionalArgument.new('subcommand', subcommand: true)
62
+ end
63
+
64
+ def options_first(enable = true)
65
+ @options_first = enable
66
+ end
67
+
68
+ def options_first?
69
+ @options_first ? true : false
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/base_option'
4
+
5
+ module EacCli
6
+ class Definition
7
+ class ArgumentOption < ::EacCli::Definition::BaseOption
8
+ def argument?
9
+ true
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,7 +3,7 @@
3
3
  require 'eac_ruby_utils/core_ext'
4
4
 
5
5
  module EacCli
6
- module Runner
6
+ class Definition
7
7
  class BaseOption
8
8
  attr_reader :short, :long, :description, :options
9
9
 
@@ -14,6 +14,10 @@ module EacCli
14
14
  @options = options.with_indifferent_access
15
15
  end
16
16
 
17
+ def identifier
18
+ long.to_s.variableize.to_sym
19
+ end
20
+
17
21
  def show_on_usage?
18
22
  options[:usage]
19
23
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/base_option'
4
+
5
+ module EacCli
6
+ class Definition
7
+ class BooleanOption < ::EacCli::Definition::BaseOption
8
+ def argument?
9
+ false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,10 +3,14 @@
3
3
  require 'eac_ruby_utils/core_ext'
4
4
 
5
5
  module EacCli
6
- module Runner
6
+ class Definition
7
7
  class PositionalArgument
8
8
  common_constructor :name, :options, default: [{}]
9
9
 
10
+ def identifier
11
+ name.to_s.variableize.to_sym
12
+ end
13
+
10
14
  def optional?
11
15
  options[:optional]
12
16
  end
@@ -4,8 +4,8 @@ require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_ruby_utils/console/docopt_runner'
5
5
 
6
6
  module EacCli
7
- module Runner
8
- class DocoptDoc
7
+ module Docopt
8
+ class DocBuilder
9
9
  common_constructor :definition
10
10
 
11
11
  SEP = ' '
@@ -51,15 +51,22 @@ module EacCli
51
51
  end
52
52
 
53
53
  def self_usage
54
- b = IDENT + ::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO
55
- b += "#{SEP}[options]" if definition.options_argument
56
- b + self_usage_arguments
54
+ IDENT + self_usage_arguments.join(SEP)
57
55
  end
58
56
 
59
57
  def self_usage_arguments
60
- definition.options.select(&:show_on_usage?)
61
- .map { |option| "#{SEP}#{option_argument(option)}" }.join +
62
- definition.positional.map { |p| "#{SEP}#{positional_argument(p)}" }.join
58
+ [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
59
+ definition.options_argument.if_present([]) { |_v| ['[options]'] } +
60
+ self_usage_arguments_options +
61
+ self_usage_arguments_positional
62
+ end
63
+
64
+ def self_usage_arguments_options
65
+ definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
66
+ end
67
+
68
+ def self_usage_arguments_positional
69
+ definition.positional.map { |p| positional_argument(p) }
63
70
  end
64
71
 
65
72
  def to_s
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/docopt/doc_builder'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+
6
+ module EacCli
7
+ module Docopt
8
+ module RunnerExtension
9
+ extend ::ActiveSupport::Concern
10
+
11
+ included do
12
+ singleton_class.prepend ClassMethods
13
+ prepend InstanceMethods
14
+ end
15
+
16
+ class << self
17
+ def check(klass)
18
+ return unless klass < ::EacRubyUtils::Console::DocoptRunner
19
+
20
+ klass.include(self)
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ def create(*context_args)
26
+ r = new(*context_args)
27
+ r.context = ::EacCli::Runner::Context.new(*context_args)
28
+ r
29
+ end
30
+ end
31
+
32
+ module InstanceMethods
33
+ def doc
34
+ ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
35
+ end
36
+
37
+ def docopt_options
38
+ super.merge(options_first: self.class.runner_definition.options_first?)
39
+ end
40
+ end
41
+
42
+ def extra_available_subcommands
43
+ self.class.constants
44
+ .map { |name| self.class.const_get(name) }
45
+ .select { |c| c.instance_of? Class }
46
+ .select { |c| c.included_modules.include?(::EacCli::Runner) }
47
+ .map { |c| c.name.demodulize.underscore.dasherize }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Parser
7
+ require_sub __FILE__
8
+ common_constructor :definition
9
+
10
+ def parse(argv)
11
+ ::EacCli::Parser::ParseResult.new(definition, argv).result
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/struct'
5
+
6
+ module EacCli
7
+ class Parser
8
+ class Collector
9
+ class << self
10
+ def to_data(definition)
11
+ collector = new(definition)
12
+ yield(collector)
13
+ collector.to_data
14
+ end
15
+ end
16
+
17
+ common_constructor :definition do
18
+ default_values
19
+ end
20
+
21
+ # @return [OpenStruct]
22
+ def to_data
23
+ ::EacRubyUtils::Struct.new(data.transform_keys(&:identifier))
24
+ end
25
+
26
+ def collect(option, value)
27
+ if data[option].is_a?(::Array)
28
+ data[option] << value
29
+ else
30
+ data[option] = value
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def data
37
+ @data ||= {}
38
+ end
39
+
40
+ def default_values
41
+ definition.options.each { |option| data[option] = option_default_value(option) }
42
+ definition.positional.each do |positional|
43
+ data[positional] = positional_default_value(positional)
44
+ end
45
+ end
46
+
47
+ def option_default_value(option)
48
+ option.argument? ? nil : false
49
+ end
50
+
51
+ def positional_default_value(positional)
52
+ positional.repeat? ? [] : nil
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Parser
7
+ class Error < ::StandardError
8
+ def initialize(definition, argv, message)
9
+ @definition = definition
10
+ @argv = argv
11
+ super(message)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'optparse'
5
+
6
+ module EacCli
7
+ class Parser
8
+ class OptionsCollection
9
+ SEP = ' '
10
+ IDENT = SEP * 2
11
+ OPTION_DESC_SEP = IDENT * 2
12
+
13
+ enable_simple_cache
14
+ common_constructor(:definition, :argv, :collector) { collect }
15
+ attr_reader :arguments
16
+
17
+ private
18
+
19
+ def collect
20
+ build_banner
21
+ build_options
22
+ @arguments = option_parser.parse(argv)
23
+ end
24
+
25
+ def option_parser_uncached
26
+ ::OptionParser.new
27
+ end
28
+
29
+ def build_banner
30
+ option_parser.banner = "#{definition.description}\n\n#{section('usage')}"
31
+ end
32
+
33
+ def build_options
34
+ definition.options.each do |option|
35
+ build_option(option)
36
+ end
37
+ end
38
+
39
+ def build_option(option)
40
+ option_parser.on(
41
+ *[option_short(option), option_long(option), option.description].reject(&:blank?)
42
+ ) do |value|
43
+ collector.collect(option, value)
44
+ end
45
+ end
46
+
47
+ def positional_argument(positional)
48
+ if positional.subcommand?
49
+ ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
50
+ else
51
+ r = "<#{positional.name}>"
52
+ r += '...' if positional.repeat?
53
+ r = "[#{r}]" if positional.optional?
54
+ r
55
+ end
56
+ end
57
+
58
+ def option_argument(option)
59
+ option_long(option)
60
+ end
61
+
62
+ def option_long(option)
63
+ b = option.long
64
+ b += '=VALUE' if option.argument?
65
+ b
66
+ end
67
+
68
+ def option_short(option)
69
+ b = option.short
70
+ b += 'VALUE' if option.argument?
71
+ b
72
+ end
73
+
74
+ def section(header, include_header = true)
75
+ b = include_header ? "#{header.humanize}:\n" : ''
76
+ b += send("self_#{header}") + "\n"
77
+ # TO-DO: implement alternatives
78
+ b
79
+ end
80
+
81
+ def self_options
82
+ definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
83
+ end
84
+
85
+ def self_usage
86
+ IDENT + self_usage_arguments.join(SEP)
87
+ end
88
+
89
+ def self_usage_arguments
90
+ [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
91
+ definition.options_argument.if_present([]) { |_v| ['[options]'] } +
92
+ self_usage_arguments_options +
93
+ self_usage_arguments_positional
94
+ end
95
+
96
+ def self_usage_arguments_options
97
+ definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
98
+ end
99
+
100
+ def self_usage_arguments_positional
101
+ definition.positional.map { |p| positional_argument(p) }
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Parser
7
+ class ParseResult
8
+ common_constructor :definition, :argv
9
+
10
+ def result
11
+ ::EacCli::Parser::Collector.to_data(definition) do |collector|
12
+ ::EacCli::Parser::PositionalCollection.new(
13
+ definition,
14
+ ::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
15
+ collector
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_cli/parser/error'
5
+
6
+ module EacCli
7
+ class Parser
8
+ class PositionalCollection
9
+ common_constructor(:definition, :argv, :collector) { collect }
10
+
11
+ private
12
+
13
+ def collected
14
+ @collected ||= ::Set.new
15
+ end
16
+
17
+ def collect
18
+ argv.each { |argv_value| colect_argv_value(argv_value) }
19
+ return unless pending_required_positional?
20
+
21
+ raise ::EacCli::Parser::Error.new(
22
+ definition, argv, 'No value for required positional ' \
23
+ "\"#{current_positional.identifier}\""
24
+ )
25
+ end
26
+
27
+ def colect_argv_value(argv_value)
28
+ collector.collect(current_positional, argv_value)
29
+ collected << current_positional
30
+ positional_enumerator.next unless current_positional.repeat?
31
+ end
32
+
33
+ def pending_required_positional?
34
+ !(current_positional.blank? || current_positional.optional? ||
35
+ collected.include?(current_positional))
36
+ end
37
+
38
+ def positional_enumerator
39
+ @positional_enumerator ||= definition.positional.each
40
+ end
41
+
42
+ def current_positional
43
+ positional_enumerator.peek
44
+ rescue ::StopIteration
45
+ nil
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,33 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/runner/definition'
4
- require 'eac_cli/runner/docopt_doc'
3
+ require 'eac_cli/definition'
4
+ require 'eac_cli/docopt/runner_extension'
5
+ require 'eac_cli/parser'
5
6
  require 'eac_ruby_utils/core_ext'
6
7
 
7
8
  module EacCli
8
9
  module Runner
10
+ require_sub __FILE__
9
11
  extend ::ActiveSupport::Concern
10
12
 
11
13
  included do
12
14
  extend ClassMethods
13
15
  include InstanceMethods
16
+ ::EacCli::Docopt::RunnerExtension.check(self)
14
17
  end
15
18
 
16
19
  module ClassMethods
20
+ def create(*context_args)
21
+ r = new
22
+ r.context = ::EacCli::Runner::Context.new(*context_args)
23
+ r
24
+ end
25
+
17
26
  def runner_definition(&block)
18
- @runner_definition ||= ::EacCli::Runner::Definition.new
27
+ @runner_definition ||= ::EacCli::Definition.new
19
28
  @runner_definition.instance_eval(&block) if block
20
29
  @runner_definition
21
30
  end
22
31
  end
23
32
 
24
33
  module InstanceMethods
25
- def doc
26
- ::EacCli::Runner::DocoptDoc.new(self.class.runner_definition).to_s
34
+ def context
35
+ return @context if @context
36
+
37
+ raise 'Context was required, but was not set yet'
38
+ end
39
+
40
+ def context=(new_context)
41
+ @context = new_context
42
+ @parsed = nil
27
43
  end
28
44
 
29
- def docopt_options
30
- super.merge(options_first: self.class.runner_definition.options_first?)
45
+ def parsed
46
+ @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(context.argv)
31
47
  end
32
48
  end
33
49
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module Runner
7
+ class Context
8
+ attr_reader :argv, :parent, :program_name
9
+
10
+ def initialize(*context_args)
11
+ options = context_args.extract_options!
12
+ @argv = (context_args[0] || options.delete(:argv)).freeze
13
+ @parent = context_args[1] || options.delete(:parent)
14
+ @program_name = options.delete(:program_name)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-25 00:00:00.000000000 Z
11
+ date: 2020-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.23'
19
+ version: '0.45'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.23'
26
+ version: '0.45'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: eac_ruby_gem_support
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.1.2
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
43
  version: '0.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.2
41
47
  description:
42
48
  email:
43
49
  executables: []
@@ -47,13 +53,21 @@ files:
47
53
  - Gemfile
48
54
  - lib/eac_cli.rb
49
55
  - lib/eac_cli/default_runner.rb
56
+ - lib/eac_cli/definition.rb
57
+ - lib/eac_cli/definition/argument_option.rb
58
+ - lib/eac_cli/definition/base_option.rb
59
+ - lib/eac_cli/definition/boolean_option.rb
60
+ - lib/eac_cli/definition/positional_argument.rb
61
+ - lib/eac_cli/docopt/doc_builder.rb
62
+ - lib/eac_cli/docopt/runner_extension.rb
63
+ - lib/eac_cli/parser.rb
64
+ - lib/eac_cli/parser/collector.rb
65
+ - lib/eac_cli/parser/error.rb
66
+ - lib/eac_cli/parser/options_collection.rb
67
+ - lib/eac_cli/parser/parse_result.rb
68
+ - lib/eac_cli/parser/positional_collection.rb
50
69
  - lib/eac_cli/runner.rb
51
- - lib/eac_cli/runner/argument_option.rb
52
- - lib/eac_cli/runner/base_option.rb
53
- - lib/eac_cli/runner/boolean_option.rb
54
- - lib/eac_cli/runner/definition.rb
55
- - lib/eac_cli/runner/docopt_doc.rb
56
- - lib/eac_cli/runner/positional_argument.rb
70
+ - lib/eac_cli/runner/context.rb
57
71
  - lib/eac_cli/version.rb
58
72
  homepage:
59
73
  licenses: []
@@ -73,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  requirements: []
76
- rubygems_version: 3.0.6
90
+ rubygems_version: 3.0.8
77
91
  signing_key:
78
92
  specification_version: 4
79
93
  summary: Utilities to build CLI applications with Ruby.
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/runner/base_option'
4
-
5
- module EacCli
6
- module Runner
7
- class ArgumentOption < ::EacCli::Runner::BaseOption
8
- def argument?
9
- true
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/runner/base_option'
4
-
5
- module EacCli
6
- module Runner
7
- class BooleanOption < ::EacCli::Runner::BaseOption
8
- def argument?
9
- false
10
- end
11
- end
12
- end
13
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/runner/argument_option'
4
- require 'eac_cli/runner/boolean_option'
5
- require 'eac_cli/runner/positional_argument'
6
- require 'eac_ruby_utils/core_ext'
7
-
8
- module EacCli
9
- module Runner
10
- class Definition
11
- require_sub __FILE__
12
- attr_accessor :description
13
- attr_accessor :options_argument
14
-
15
- def initialize
16
- self.description = '-- NO DESCRIPTION SET --'
17
- self.options_argument = true
18
- end
19
-
20
- def alt(&block)
21
- r = ::EacCli::Runner::Definition.new
22
- r.instance_eval(&block)
23
- alternatives << r
24
- r
25
- end
26
-
27
- def alternatives
28
- @alternatives ||= []
29
- end
30
-
31
- def arg_opt(short, long, description, option_options = {})
32
- options << ArgumentOption.new(short, long, description, option_options)
33
- end
34
-
35
- def bool_opt(short, long, description, option_options = {})
36
- options << BooleanOption.new(short, long, description, option_options)
37
- end
38
-
39
- def desc(description)
40
- self.description = description
41
- end
42
-
43
- def options_arg(options_argument)
44
- self.options_argument = options_argument
45
- end
46
-
47
- def options
48
- @options ||= []
49
- end
50
-
51
- def pos_arg(name, arg_options = {})
52
- positional << PositionalArgument.new(name, arg_options)
53
- end
54
-
55
- def positional
56
- @positional ||= []
57
- end
58
-
59
- def subcommands
60
- positional << PositionalArgument.new('subcommand', subcommand: true)
61
- end
62
-
63
- def options_first(enable = true)
64
- @options_first = enable
65
- end
66
-
67
- def options_first?
68
- @options_first ? true : false
69
- end
70
- end
71
- end
72
- end