avm-tools 0.74.0 → 0.76.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/eac_rails_base0/instance.rb +2 -5
  3. data/lib/avm/{rails/runners.rb → eac_rails_base1.rb} +2 -4
  4. data/lib/avm/{rails → eac_rails_base1}/instance.rb +8 -3
  5. data/lib/avm/eac_rails_base1/runner.rb +12 -0
  6. data/lib/avm/eac_rails_base1/runner/bundle.rb +28 -0
  7. data/lib/avm/eac_rails_base1/runner/code_runner.rb +28 -0
  8. data/lib/avm/eac_rails_base1/runner_with/bundle.rb +57 -0
  9. data/lib/avm/eac_redmine_base0/instance.rb +2 -4
  10. data/lib/avm/{stereotypes/eac_ubuntu_base0.rb → eac_ubuntu_base0.rb} +1 -3
  11. data/lib/avm/eac_webapp_base0/deploy.rb +17 -40
  12. data/lib/avm/eac_webapp_base0/deploy/build.rb +48 -0
  13. data/lib/avm/eac_webapp_base0/deploy/git_info.rb +13 -0
  14. data/lib/avm/eac_webapp_base0/deploy/version.rb +4 -0
  15. data/lib/avm/eac_webapp_base0/deploy/write_on_target.rb +18 -0
  16. data/lib/avm/eac_webapp_base0/instance.rb +2 -2
  17. data/lib/avm/eac_webapp_base0/runner.rb +12 -0
  18. data/lib/avm/eac_webapp_base0/runner/apache_host.rb +2 -3
  19. data/lib/avm/eac_webapp_base0/runner/data.rb +1 -1
  20. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +1 -1
  21. data/lib/avm/eac_webapp_base0/runner/data/load.rb +1 -1
  22. data/lib/avm/eac_webapp_base0/runner/deploy.rb +4 -16
  23. data/lib/avm/eac_wordpress_base0.rb +9 -0
  24. data/lib/avm/eac_wordpress_base0/apache_host.rb +25 -0
  25. data/lib/avm/eac_wordpress_base0/deploy.rb +10 -0
  26. data/lib/avm/eac_wordpress_base0/instance.rb +24 -0
  27. data/lib/avm/eac_writings_base0/apache_host.rb +17 -0
  28. data/lib/avm/eac_writings_base0/deploy.rb +36 -0
  29. data/lib/avm/eac_writings_base0/instance.rb +11 -0
  30. data/lib/avm/files/appendable.rb +55 -0
  31. data/lib/avm/files/appendable/file_content.rb +24 -0
  32. data/lib/avm/files/appendable/plain_directory.rb +25 -0
  33. data/lib/avm/files/appendable/resource_base.rb +13 -0
  34. data/lib/avm/files/appendable/tar_output_command.rb +26 -0
  35. data/lib/avm/files/appendable/templatized_directory.rb +28 -0
  36. data/lib/avm/files/appender.rb +11 -0
  37. data/lib/avm/files/deploy.rb +72 -0
  38. data/lib/avm/files/formatter.rb +8 -4
  39. data/lib/avm/git/auto_commit_path.rb +2 -4
  40. data/lib/avm/git/auto_commit_path/ruby.rb +20 -0
  41. data/lib/avm/git/commit/deploy.rb +8 -61
  42. data/lib/avm/instances/runner.rb +40 -0
  43. data/lib/avm/{stereotypes/postgresql.rb → postgresql.rb} +1 -3
  44. data/lib/avm/postgresql/instance.rb +63 -0
  45. data/lib/avm/postgresql/instance/data_unit.rb +39 -0
  46. data/lib/avm/postgresql/instance_with.rb +18 -0
  47. data/lib/avm/tools/runner.rb +3 -3
  48. data/lib/avm/tools/runner/eac_rails_base0.rb +5 -18
  49. data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +1 -1
  50. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +7 -12
  51. data/lib/avm/tools/runner/eac_rails_base0/runner.rb +3 -3
  52. data/lib/avm/tools/runner/eac_redmine_base0.rb +5 -23
  53. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +1 -1
  54. data/lib/avm/tools/runner/eac_redmine_base0/docker.rb +1 -1
  55. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +9 -18
  56. data/lib/avm/tools/runner/eac_wordpress_base0.rb +5 -24
  57. data/lib/avm/tools/runner/{eac_rails_base0/data.rb → eac_writings_base0.rb} +4 -4
  58. data/lib/avm/tools/runner/files/format.rb +3 -2
  59. data/lib/avm/tools/runner/git/auto_commit.rb +11 -0
  60. data/lib/avm/tools/runner/git/deploy.rb +1 -1
  61. data/lib/avm/tools/version.rb +1 -1
  62. data/template/avm/{stereotypes/eac_ubuntu_base0 → eac_ubuntu_base0}/docker_image/Dockerfile +0 -0
  63. data/template/avm/{stereotypes/eac_wordpress_base0 → eac_wordpress_base0}/deploy/wp-config.php.template +0 -0
  64. data/template/avm/eac_writings_base0/deploy/index.html.template +9 -0
  65. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  66. data/vendor/eac_cli/lib/eac_cli/definition.rb +35 -3
  67. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  68. data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
  69. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  70. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  71. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  72. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +27 -64
  73. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +17 -0
  74. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +47 -19
  75. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  76. data/vendor/eac_cli/lib/eac_cli/runner.rb +4 -0
  77. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  78. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  79. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
  80. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +48 -40
  81. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -39
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  89. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  90. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  91. metadata +48 -33
  92. data/lib/avm/git/commit/deploy/appended.rb +0 -37
  93. data/lib/avm/git/commit/deploy/appended/base.rb +0 -17
  94. data/lib/avm/git/commit/deploy/appended/directory.rb +0 -32
  95. data/lib/avm/git/commit/deploy/appended/file_content.rb +0 -28
  96. data/lib/avm/rails/runners/bundle.rb +0 -35
  97. data/lib/avm/rails/runners/runner.rb +0 -48
  98. data/lib/avm/stereotypes/eac_wordpress_base0/apache_host.rb +0 -27
  99. data/lib/avm/stereotypes/eac_wordpress_base0/deploy.rb +0 -12
  100. data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +0 -26
  101. data/lib/avm/stereotypes/postgresql/instance.rb +0 -65
  102. data/lib/avm/stereotypes/postgresql/instance/data_unit.rb +0 -41
  103. data/lib/avm/stereotypes/postgresql/instance_with.rb +0 -20
  104. data/lib/avm/stereotypes/rails.rb +0 -11
  105. data/lib/avm/tools/runner/eac_rails_base0/apache_host.rb +0 -16
  106. data/lib/avm/tools/runner/eac_rails_base0/bundle.rb +0 -14
  107. data/lib/avm/tools/runner/eac_rails_base0/deploy.rb +0 -15
  108. data/lib/avm/tools/runner/eac_redmine_base0/bundle.rb +0 -14
  109. data/lib/avm/tools/runner/eac_redmine_base0/data.rb +0 -27
  110. data/lib/avm/tools/runner/eac_redmine_base0/data/dump.rb +0 -16
  111. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +0 -15
  112. data/lib/avm/tools/runner/eac_redmine_base0/runner.rb +0 -14
  113. data/lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb +0 -17
  114. data/lib/avm/tools/runner/eac_wordpress_base0/data.rb +0 -15
  115. data/lib/avm/tools/runner/eac_wordpress_base0/deploy.rb +0 -15
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/rails/runners/runner'
3
+ require 'avm/eac_rails_base1/runner/code_runner'
4
4
 
5
5
  module Avm
6
6
  module Tools
7
7
  class Runner < ::EacRubyUtils::Console::DocoptRunner
8
- class EacRailsBase0 < ::EacRubyUtils::Console::DocoptRunner
9
- class Runner < ::Avm::Rails::Runners::Runner
8
+ class EacRailsBase0 < ::Avm::EacRailsBase1::Runner
9
+ class Runner < ::Avm::EacRailsBase1::Runner::CodeRunner
10
10
  end
11
11
  end
12
12
  end
@@ -1,33 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/eac_rails_base1/runner'
4
+ require 'avm/eac_redmine_base0'
3
5
  require 'eac_ruby_utils/console/docopt_runner'
4
- require 'eac_ruby_utils/simple_cache'
5
- require 'avm/eac_redmine_base0/instance'
6
- require 'eac_ruby_utils/require_sub'
7
- ::EacRubyUtils.require_sub(__FILE__)
6
+ require 'eac_ruby_utils/core_ext'
8
7
 
9
8
  module Avm
10
9
  module Tools
11
10
  class Runner < ::EacRubyUtils::Console::DocoptRunner
12
- class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
13
- include ::EacRubyUtils::SimpleCache
14
-
15
- DOC = <<~DOCOPT
16
- Utilities for EacRedmineBase0 instances.
17
-
18
- Usage:
19
- __PROGRAM__ [options] <instance_id> __SUBCOMMANDS__
20
- __PROGRAM__ -h | --help
21
-
22
- Options:
23
- -h --help Show this screen.
24
- DOCOPT
25
-
26
- private
27
-
28
- def instance_uncached
29
- ::Avm::EacRedmineBase0::Instance.by_id(options['<instance_id>'])
30
- end
11
+ class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
12
+ require_sub __FILE__
31
13
  end
32
14
  end
33
15
  end
@@ -8,7 +8,7 @@ require 'eac_ruby_utils/core_ext'
8
8
  module Avm
9
9
  module Tools
10
10
  class Runner < ::EacRubyUtils::Console::DocoptRunner
11
- class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
11
+ class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
12
12
  class CoreUpdate < ::EacRubyUtils::Console::DocoptRunner
13
13
  include ::EacCli::DefaultRunner
14
14
 
@@ -5,7 +5,7 @@ require 'avm/docker/runner'
5
5
  module Avm
6
6
  module Tools
7
7
  class Runner < ::EacRubyUtils::Console::DocoptRunner
8
- class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
8
+ class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
9
9
  class Docker < ::Avm::Docker::Runner
10
10
  end
11
11
  end
@@ -1,23 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/rails/runners/runner'
4
- require 'eac_cli/default_runner'
3
+ require 'eac_cli/core_ext'
4
+ require 'avm/eac_rails_base1/runner/code_runner'
5
5
 
6
6
  module Avm
7
7
  module Tools
8
8
  class Runner < ::EacRubyUtils::Console::DocoptRunner
9
- class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
10
- class ProjectRename < ::Avm::Rails::Runners::Runner
11
- include ::EacCli::DefaultRunner
12
-
13
- runner_definition do
9
+ class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
10
+ class ProjectRename
11
+ runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle do
14
12
  pos_arg :from
15
13
  pos_arg :to
16
14
  end
17
15
 
18
16
  def run
19
- start_banner
20
- command.system!
17
+ bundle_run
21
18
  end
22
19
 
23
20
  def start_banner
@@ -25,16 +22,10 @@ module Avm
25
22
  infov 'To', to
26
23
  end
27
24
 
28
- def from
29
- options.fetch('<from>')
30
- end
31
-
32
- def to
33
- options.fetch('<to>')
34
- end
25
+ delegate :from, :to, to: :parsed
35
26
 
36
- def command
37
- context(:instance).bundle('exec', 'rails', 'runner', code)
27
+ def bundle_args
28
+ %w[exec rails runner] + [code]
38
29
  end
39
30
 
40
31
  def code
@@ -1,34 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/eac_webapp_base0/runner'
4
+ require 'avm/eac_wordpress_base0'
3
5
  require 'eac_ruby_utils/console/docopt_runner'
4
- require 'eac_ruby_utils/simple_cache'
5
- require 'avm/stereotypes/eac_wordpress_base0/instance'
6
- require 'avm/tools/runner/eac_wordpress_base0/apache_host'
7
- require 'avm/tools/runner/eac_wordpress_base0/data'
8
- require 'avm/tools/runner/eac_wordpress_base0/deploy'
6
+ require 'eac_ruby_utils/core_ext'
9
7
 
10
8
  module Avm
11
9
  module Tools
12
10
  class Runner < ::EacRubyUtils::Console::DocoptRunner
13
- class EacWordpressBase0 < ::EacRubyUtils::Console::DocoptRunner
14
- include ::EacRubyUtils::SimpleCache
15
-
16
- DOC = <<~DOCOPT
17
- Utilities for EacWordpressBase0 instances.
18
-
19
- Usage:
20
- __PROGRAM__ [options] <instance_id> __SUBCOMMANDS__
21
- __PROGRAM__ -h | --help
22
-
23
- Options:
24
- -h --help Show this screen.
25
- DOCOPT
26
-
27
- private
28
-
29
- def instance_uncached
30
- ::Avm::Stereotypes::EacWordpressBase0::Instance.by_id(options['<instance_id>'])
31
- end
11
+ class EacWordpressBase0 < ::Avm::EacWebappBase0::Runner
12
+ require_sub __FILE__
32
13
  end
33
14
  end
34
15
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/eac_webapp_base0/runner/data'
3
+ require 'avm/eac_webapp_base0/runner'
4
+ require 'avm/eac_writings_base0'
4
5
  require 'eac_ruby_utils/console/docopt_runner'
5
6
 
6
7
  module Avm
7
8
  module Tools
8
9
  class Runner < ::EacRubyUtils::Console::DocoptRunner
9
- class EacRailsBase0 < ::EacRubyUtils::Console::DocoptRunner
10
- class Data < ::Avm::EacWebappBase0::Runner::Data
11
- end
10
+ class EacWritingsBase0 < ::Avm::EacWebappBase0::Runner
11
+ require_sub __FILE__
12
12
  end
13
13
  end
14
14
  end
@@ -32,8 +32,9 @@ module Avm
32
32
  end
33
33
 
34
34
  def formatter_options
35
- { apply: options.fetch('--apply'), recursive: !options.fetch('--no-recursive'),
36
- verbose: options.fetch('--verbose') }
35
+ { ::Avm::Files::Formatter::OPTION_APPLY => options.fetch('--apply'),
36
+ ::Avm::Files::Formatter::OPTION_RECURSIVE => !options.fetch('--no-recursive'),
37
+ ::Avm::Files::Formatter::OPTION_VERBOSE => options.fetch('--verbose') }
37
38
  end
38
39
 
39
40
  def git
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/git/auto_commit_path'
4
+ require 'avm/files/formatter'
4
5
  require 'eac_cli/default_runner'
5
6
 
6
7
  module Avm
@@ -13,12 +14,14 @@ module Avm
13
14
  runner_definition do
14
15
  desc 'Commit with message based in content commited.'
15
16
  bool_opt '-d', '--dirty', 'Select dirty files.'
17
+ bool_opt '-f', '--format', 'Format files before commit.'
16
18
  pos_arg 'paths', repeat: true, optional: true
17
19
  end
18
20
 
19
21
  def run
20
22
  clear_stage
21
23
  banner
24
+ format_files
22
25
  run_paths
23
26
  end
24
27
 
@@ -39,6 +42,14 @@ module Avm
39
42
  context(:git).dirty_files.map { |d| context(:git).root_path.join / d.path }
40
43
  end
41
44
 
45
+ def format_files
46
+ return unless options.fetch('--format')
47
+
48
+ infom 'Formating files...'
49
+ ::Avm::Files::Formatter.new(paths.map(&:path),
50
+ ::Avm::Files::Formatter::OPTION_APPLY => true).run
51
+ end
52
+
42
53
  def paths_uncached
43
54
  (options.fetch('<paths>')
44
55
  .map { |p| p.to_pathname.expand_path } + dirty_paths)
@@ -88,7 +88,7 @@ module Avm
88
88
  def deploy
89
89
  ::Avm::Git::Commit.new(git, reference_sha1)
90
90
  .deploy_to_url(target_url)
91
- .append_directories(appended_directories)
91
+ .append_templatized_directories(appended_directories)
92
92
  .variables_source_set(variables_source)
93
93
  .run
94
94
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.74.0'
5
+ VERSION = '0.76.1'
6
6
  end
7
7
  end
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <title>%%title%%</title>
4
+ </head>
5
+ <body>
6
+ <h1>%%title%%</h1>
7
+ <a href="%%pdf_path%%">PDF</a>
8
+ </body>
9
+ </html>
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*', 'Gemfile']
14
14
 
15
- s.add_dependency 'eac_ruby_utils', '~> 0.45'
15
+ s.add_dependency 'eac_ruby_utils', '~> 0.50'
16
16
 
17
17
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
18
18
  end
@@ -8,6 +8,10 @@ require 'eac_ruby_utils/core_ext'
8
8
  module EacCli
9
9
  class Definition
10
10
  require_sub __FILE__
11
+
12
+ SUBCOMMAND_NAME_ARG = 'subcommand'
13
+ SUBCOMMAND_ARGS_ARG = 'subcommand_args'
14
+
11
15
  attr_accessor :description
12
16
  attr_accessor :options_argument
13
17
 
@@ -41,6 +45,10 @@ module EacCli
41
45
  self.description = description
42
46
  end
43
47
 
48
+ def help_formatter
49
+ @help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
50
+ end
51
+
44
52
  def options_arg(options_argument)
45
53
  self.options_argument = options_argument
46
54
  end
@@ -50,15 +58,33 @@ module EacCli
50
58
  end
51
59
 
52
60
  def pos_arg(name, arg_options = {})
53
- positional << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
61
+ new_pos_arg = ::EacCli::Definition::PositionalArgument.new(name, arg_options)
62
+ raise 'Positional arguments are blocked' if positional_arguments_blocked?(new_pos_arg)
63
+
64
+ pos_set << new_pos_arg
54
65
  end
55
66
 
56
67
  def positional
57
- @positional ||= []
68
+ pos_set.to_a
69
+ end
70
+
71
+ def positional_arguments_blocked?(new_pos_arg)
72
+ last = pos_set.last
73
+ return false unless last
74
+ return true if last.repeat?
75
+ return true if last.optional? && new_pos_arg.required?
76
+
77
+ false
58
78
  end
59
79
 
60
80
  def subcommands
61
- positional << ::EacCli::Definition::PositionalArgument.new('subcommand', subcommand: true)
81
+ pos_arg(SUBCOMMAND_NAME_ARG, subcommand: true)
82
+ pos_set << ::EacCli::Definition::PositionalArgument.new(SUBCOMMAND_ARGS_ARG,
83
+ optional: true, repeat: true)
84
+ end
85
+
86
+ def subcommands?
87
+ pos_set.any?(&:subcommand?)
62
88
  end
63
89
 
64
90
  def options_first(enable = true)
@@ -68,5 +94,11 @@ module EacCli
68
94
  def options_first?
69
95
  @options_first ? true : false
70
96
  end
97
+
98
+ private
99
+
100
+ def pos_set
101
+ @pos_set ||= []
102
+ end
71
103
  end
72
104
  end
@@ -5,19 +5,35 @@ require 'eac_ruby_utils/core_ext'
5
5
  module EacCli
6
6
  class Definition
7
7
  class BaseOption
8
+ DEFAULT_REQUIRED = false
9
+
10
+ enable_listable
11
+ lists.add_symbol :option, :optional, :usage, :required
8
12
  attr_reader :short, :long, :description, :options
9
13
 
10
14
  def initialize(short, long, description, options = {})
11
15
  @short = short
12
16
  @long = long
13
17
  @description = description
14
- @options = options.with_indifferent_access
18
+ @options = options.symbolize_keys
19
+ @options.assert_valid_keys(::EacCli::Definition::BaseOption.lists.option.values)
15
20
  end
16
21
 
17
22
  def identifier
18
23
  long.to_s.variableize.to_sym
19
24
  end
20
25
 
26
+ def required?
27
+ return true if options.key?(:required) && options.fetch(:required)
28
+ return false if options.key?(:optional) && options.fetch(:optional)
29
+
30
+ DEFAULT_REQUIRED
31
+ end
32
+
33
+ def to_s
34
+ "#{self.class.name.demodulize}[#{identifier}]"
35
+ end
36
+
21
37
  def show_on_usage?
22
38
  options[:usage]
23
39
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Definition
7
+ class HelpFormatter
8
+ SEP = ' '
9
+ IDENT = SEP * 2
10
+ OPTION_DESC_SEP = IDENT * 2
11
+
12
+ class << self
13
+ def option_long(option)
14
+ b = option.long
15
+ b += '=VALUE' if option.argument?
16
+ b
17
+ end
18
+
19
+ def option_short(option)
20
+ b = option.short
21
+ b += 'VALUE' if option.argument?
22
+ b
23
+ end
24
+ end
25
+
26
+ common_constructor :definition
27
+
28
+ def positional_argument(positional)
29
+ if positional.subcommand?
30
+ ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
31
+ else
32
+ r = "<#{positional.name}>"
33
+ r += '...' if positional.repeat?
34
+ r = "[#{r}]" if positional.optional?
35
+ r
36
+ end
37
+ end
38
+
39
+ def section(header, include_header = true)
40
+ b = include_header ? "#{header.humanize}:\n" : ''
41
+ b += send("self_#{header}") + "\n"
42
+ # TO-DO: implement alternatives
43
+ b
44
+ end
45
+
46
+ def self_options
47
+ definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
48
+ end
49
+
50
+ def self_usage
51
+ IDENT + self_usage_arguments.join(SEP)
52
+ end
53
+
54
+ def self_usage_arguments
55
+ [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
56
+ definition.options_argument.if_present([]) { |_v| ['[options]'] } +
57
+ self_usage_arguments_options +
58
+ self_usage_arguments_positional
59
+ end
60
+
61
+ def self_usage_arguments_options
62
+ definition.options.select(&:show_on_usage?).map do |option|
63
+ self.class.option_long(option)
64
+ end
65
+ end
66
+
67
+ def self_usage_arguments_positional
68
+ definition.positional.map { |p| positional_argument(p) }
69
+ end
70
+
71
+ def to_banner
72
+ "#{definition.description}\n\n#{section('usage')}"
73
+ end
74
+ end
75
+ end
76
+ end