eac_cli 0.4.0 → 0.7.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e2305c2b18d413d495a33e51960457e7dac373738a7d27dff2827467c473ff1
4
- data.tar.gz: 6a898a395163b7ba890ddb6bf6b33401dc2b35b644901a79c7c413db11237adc
3
+ metadata.gz: 2394340a91e194094ac27e21e6db64b5b6492b007ab6404843986e56f0807391
4
+ data.tar.gz: f5fc6d5e1bee5b9823de665dea129692c033b456835d6e622aa1911ee88663f8
5
5
  SHA512:
6
- metadata.gz: 5c77641706241d55d18e46c00561679f079edbdec72049b13812f470034bf6b5c1164f07cf9dadee1649194878a22fbd4679065922018e971fa369f279d746d8
7
- data.tar.gz: 184c4741948f5014aeac1704745f11accd99f3c2c514c2df2d96fd9f8458dab6aa0de993b9a4b8b79b3caf52d4ab9de5ddbb367219095c5cd90a2206db97d25f
6
+ metadata.gz: 481e7358a387eb583e4c52543800bd00f83ebb678d56a8c9998fef2559da41dcea911c79b0fc0802b4453f56d3ca70fb11a6643da6dc2f9783207c6a465e4bb7
7
+ data.tar.gz: 6d96d7e85ab52bb5be2ac121faac418780147c5491b978a170791d087ed7a9be3dcba6bc4f1f5812d0dc45ec482ea25459c63f49ce95db1df65aff196d4e8725
@@ -1,22 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/concern'
4
- require 'eac_cli/runner'
5
- require 'eac_ruby_utils/console/speaker'
6
- require 'eac_ruby_utils/simple_cache'
3
+ require 'eac_cli/runner_with/help'
4
+ require 'eac_ruby_utils/core_ext'
7
5
 
8
6
  module EacCli
9
7
  module DefaultRunner
10
- extend ::ActiveSupport::Concern
11
-
12
- included do
13
- include ::EacCli::Runner
14
- include ::EacRubyUtils::Console::Speaker
15
- include ::EacRubyUtils::SimpleCache
16
- runner_definition.alt do
17
- options_arg false
18
- bool_opt '-h', '--help', 'Show help.', usage: true
19
- end
8
+ common_concern do
9
+ include ::EacCli::RunnerWith::Help
10
+ enable_console_speaker
11
+ enable_simple_cache
20
12
  end
21
13
  end
22
14
  end
@@ -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,45 @@
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
+ prepend InstanceMethods
13
+ end
14
+
15
+ class << self
16
+ def check(klass)
17
+ return unless klass < ::EacRubyUtils::Console::DocoptRunner
18
+
19
+ ::EacCli::Runner.alias_runner_class_methods(klass, '', 'eac_cli')
20
+ ::EacCli::Runner.alias_runner_class_methods(klass, 'original', '')
21
+
22
+ klass.include(self)
23
+ end
24
+ end
25
+
26
+ module InstanceMethods
27
+ def doc
28
+ ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
29
+ end
30
+
31
+ def docopt_options
32
+ super.merge(options_first: self.class.runner_definition.options_first?)
33
+ end
34
+ end
35
+
36
+ def extra_available_subcommands
37
+ self.class.constants
38
+ .map { |name| self.class.const_get(name) }
39
+ .select { |c| c.instance_of? Class }
40
+ .select { |c| c.included_modules.include?(::EacCli::Runner) }
41
+ .map { |c| c.name.demodulize.underscore.dasherize }
42
+ end
43
+ end
44
+ end
45
+ 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,86 @@
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
 
13
+ class << self
14
+ def alias_runner_class_methods(klass, from_suffix, to_suffix)
15
+ %i[create run].each do |method|
16
+ alias_class_method(klass, build_method_name(method, from_suffix),
17
+ build_method_name(method, to_suffix))
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def alias_class_method(klass, from, to)
24
+ sklass = klass.singleton_class
25
+ return unless sklass.method_defined?(from)
26
+
27
+ sklass.alias_method to, from
28
+ end
29
+
30
+ def build_method_name(name, suffix)
31
+ ss = suffix.if_present('') { |s| "#{s}_" }
32
+ "#{ss}#{name}"
33
+ end
34
+ end
35
+
36
+ the_module = self
11
37
  included do
12
- extend ClassMethods
38
+ the_module.alias_runner_class_methods(self, '', 'original')
39
+
40
+ extend AfterClassMethods
13
41
  include InstanceMethods
42
+ ::EacCli::Docopt::RunnerExtension.check(self)
14
43
  end
15
44
 
16
- module ClassMethods
45
+ module AfterClassMethods
46
+ def create(*runner_context_args)
47
+ r = new
48
+ r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
49
+ r
50
+ end
51
+
52
+ def run(*runner_context_args)
53
+ r = create(*runner_context_args)
54
+ r.parsed
55
+ r.run
56
+ r
57
+ end
58
+
17
59
  def runner_definition(&block)
18
- @runner_definition ||= ::EacCli::Runner::Definition.new
60
+ @runner_definition ||= super_runner_definition
19
61
  @runner_definition.instance_eval(&block) if block
20
62
  @runner_definition
21
63
  end
64
+
65
+ def super_runner_definition
66
+ superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
67
+ end
22
68
  end
23
69
 
24
70
  module InstanceMethods
25
- def doc
26
- ::EacCli::Runner::DocoptDoc.new(self.class.runner_definition).to_s
71
+ def runner_context
72
+ return @runner_context if @runner_context
73
+
74
+ raise 'Context was required, but was not set yet'
75
+ end
76
+
77
+ def runner_context=(new_runner_context)
78
+ @runner_context = new_runner_context
79
+ @parsed = nil
27
80
  end
28
81
 
29
- def docopt_options
30
- super.merge(options_first: self.class.runner_definition.options_first?)
82
+ def parsed
83
+ @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(runner_context.argv)
31
84
  end
32
85
  end
33
86
  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) || ARGV).dup.freeze
13
+ @parent = context_args[1] || options.delete(:parent)
14
+ @program_name = options.delete(:program_name)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacCli
7
+ module RunnerWith
8
+ module Help
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+
12
+ runner_definition.alt do
13
+ options_arg false
14
+ bool_opt '-h', '--help', 'Show help.', usage: true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacCli
7
+ module RunnerWith
8
+ module OutputFile
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+
12
+ runner_definition do
13
+ arg_opt '-o', '--output-file', 'Output to file.'
14
+ end
15
+ end
16
+
17
+ def run_output
18
+ if parsed.output_file.present?
19
+ ::File.write(parsed.output_file, output_content)
20
+ else
21
+ out output_content
22
+ end
23
+ end
24
+ end
25
+ end
26
+ 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.7.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.7.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-27 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,24 @@ 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
71
+ - lib/eac_cli/runner_with.rb
72
+ - lib/eac_cli/runner_with/help.rb
73
+ - lib/eac_cli/runner_with/output_file.rb
57
74
  - lib/eac_cli/version.rb
58
75
  homepage:
59
76
  licenses: []
@@ -73,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
90
  - !ruby/object:Gem::Version
74
91
  version: '0'
75
92
  requirements: []
76
- rubygems_version: 3.0.6
93
+ rubygems_version: 3.0.8
77
94
  signing_key:
78
95
  specification_version: 4
79
96
  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