Sha256: 8246b94e1d80ee4711d5489736874fd50313e67371e9693e4fa4b27de045095d

Contents?: true

Size: 1.4 KB

Versions: 54

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacCli
  module RunnerWith
    module Help
      class Builder
        class Alternative
          PROGRAM_MACRO = '__PROGRAM__'
          SUBCOMMANDS_MACRO = '__SUBCOMMANDS__'

          common_constructor :alternative

          def to_s
            (
              [PROGRAM_MACRO] +
                alternative.options_argument?.if_present([]) { |_v| ['[options]'] } +
                options +
                positionals
            ).join(::EacCli::RunnerWith::Help::Builder::SEP)
          end

          def options
            alternative.options.select(&:show_on_usage?).map do |option|
              ::EacCli::RunnerWith::Help::Builder.option_long(option)
            end
          end

          def option_argument(option)
            b = option.long
            b += '=<value>' if option.argument?
            b
          end

          def positionals
            alternative.positional.map { |p| positional(p) }.reject(&:blank?)
          end

          def positional(positional)
            return unless positional.visible?

            if positional.subcommand?
              SUBCOMMANDS_MACRO
            else
              r = "<#{positional.name}>"
              r += '...' if positional.repeat?
              r = "[#{r}]" if positional.optional?
              r
            end
          end
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 3 rubygems

Version Path
eac_cli-0.27.4 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.117.1 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.117.0 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.116.2 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.27.3 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.116.1 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.27.2 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.116.0 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.27.1 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.115.0 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.27.0 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.114.2 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.114.1 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.26.2 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.114.0 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.26.1 lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.26.0 lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.113.6 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
avm-tools-0.113.5 sub/eac_cli/lib/eac_cli/runner_with/help/builder/alternative.rb
eac_cli-0.25.0 lib/eac_cli/runner_with/help/builder/alternative.rb