Sha256: a8175a8cdcd015f75822ca55595392d0c72d9a5228b6ab3b251a6443c6ac4de7

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_cli/docopt_runner'

module EacCli
  module Docopt
    class DocBuilder
      class Alternative
        common_constructor :alternative

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

        def options
          alternative.options.select(&:show_on_usage?).map do |option|
            ::EacCli::Docopt::DocBuilder.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) }
        end

        def positional(positional)
          if positional.subcommand?
            ::EacCli::DocoptRunner::SUBCOMMANDS_MACRO
          else
            r = "<#{positional.name}>"
            r += '...' if positional.repeat?
            r = "[#{r}]" if positional.optional?
            r
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
eac_cli-0.18.0 lib/eac_cli/docopt/doc_builder/alternative.rb
avm-tools-0.100.0 vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb
ehbrs-tools-0.21.0 vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb
avm-tools-0.99.1 vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb
eac_cli-0.17.0 lib/eac_cli/docopt/doc_builder/alternative.rb
avm-tools-0.99.0 vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb