eac_cli 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 744852edf04e3fbd1d56f052591c18a64d89822e17765621e2d413034561d16c
4
+ data.tar.gz: 81ae42735b990eacd912c99afa9ad577322f746b79b0bf2aecde6990ac72dfbd
5
+ SHA512:
6
+ metadata.gz: f70e6a51577955715f4d36d10856fd9af6a21aa9713b58280c1425ca44eb0c2a1cff764d20376af1ea82883da12914b6e1da1ac6dc70dfd063af898751821319
7
+ data.tar.gz: ae3b2cbf2fbaed4f8bab7ca55ba39bebf5bdeb254d596d22aafb932195ee5e2c8bb82f15c2e43fe8f4ae8e04672bb35f32785969392c484d891ea3f9802e3e1e
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
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'
7
+
8
+ module EacCli
9
+ 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
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner/definition'
4
+ require 'eac_cli/runner/docopt_doc'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacCli
8
+ module Runner
9
+ extend ::ActiveSupport::Concern
10
+
11
+ included do
12
+ extend ClassMethods
13
+ include InstanceMethods
14
+ end
15
+
16
+ module ClassMethods
17
+ def runner_definition(&block)
18
+ @runner_definition ||= ::EacCli::Runner::Definition.new
19
+ @runner_definition.instance_eval(&block) if block
20
+ @runner_definition
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def doc
26
+ ::EacCli::Runner::DocoptDoc.new(self.class.runner_definition).to_s
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module Runner
7
+ class BaseOption
8
+ attr_reader :short, :long, :description, :options
9
+
10
+ def initialize(short, long, description, options = {})
11
+ @short = short
12
+ @long = long
13
+ @description = description
14
+ @options = options.with_indifferent_access
15
+ end
16
+
17
+ def show_on_usage?
18
+ options[:usage]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,60 @@
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)
52
+ positional << PositionalArgument.new(name)
53
+ end
54
+
55
+ def positional
56
+ @positional ||= []
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+
6
+ module EacCli
7
+ module Runner
8
+ class DocoptDoc
9
+ common_constructor :definition
10
+
11
+ SEP = ' '
12
+ IDENT = SEP * 2
13
+ OPTION_DESC_SEP = IDENT * 2
14
+
15
+ def positional_argument(positional)
16
+ "<#{positional.name}>"
17
+ end
18
+
19
+ def option_argument(option)
20
+ option_long(option)
21
+ end
22
+
23
+ def option_definition(option)
24
+ option.short + SEP + option_long(option) + OPTION_DESC_SEP + option.description
25
+ end
26
+
27
+ def option_long(option)
28
+ b = option.long
29
+ b += '=<value>' if option.argument?
30
+ b
31
+ end
32
+
33
+ def section(header, include_header = true)
34
+ b = include_header ? "#{header.humanize}:\n" : ''
35
+ b += send("self_#{header}") + "\n"
36
+ definition.alternatives.each do |alternative|
37
+ b += self.class.new(alternative).section(header, false)
38
+ end
39
+ b
40
+ end
41
+
42
+ def self_options
43
+ definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
44
+ end
45
+
46
+ def self_usage
47
+ b = IDENT + ::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO
48
+ b += "#{SEP}[options]" if definition.options_argument
49
+ b + self_usage_arguments
50
+ end
51
+
52
+ def self_usage_arguments
53
+ definition.options.select(&:show_on_usage?)
54
+ .map { |option| "#{SEP}#{option_argument(option)}" }.join +
55
+ definition.positional.map { |p| "#{SEP}#{positional_argument(p)}" }.join
56
+ end
57
+
58
+ def to_s
59
+ "#{definition.description}\n\n#{section('usage')}\n#{section('options')}\n"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module Runner
7
+ class PositionalArgument
8
+ common_constructor :name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eac_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esquilo Azul Company
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_ruby_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.22'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.22'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eac_ruby_gem_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - Gemfile
48
+ - lib/eac_cli.rb
49
+ - lib/eac_cli/default_runner.rb
50
+ - 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
57
+ - lib/eac_cli/version.rb
58
+ homepage:
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.7.7
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Utilities to build CLI applications with Ruby.
81
+ test_files: []