Module: Dry::CLI::Banner::RepeatableOptionsPatch

Included in:
Dry::CLI::Banner
Defined in:
lib/space_core/cli/repeatable_options.rb

Instance Method Summary collapse

Instance Method Details

#extended_command_options(command) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/space_core/cli/repeatable_options.rb', line 58

def extended_command_options(command)
  result = command.options.map do |option|
    name = Inflector.dasherize(option.name)
    name = if option.boolean?
             "[no-]#{name}"
           elsif option.flag?
             name
           else
             # array options included: repeated flags accumulate, so show
             # the single repeatable form rather than "=VALUE1,VALUE2,..".
             "#{name}=VALUE"
           end
    name = "#{name}, #{option.alias_names.join(", ")}" if option.aliases.any?
    name = "  --#{name.ljust(30)}"
    name = "#{name}  # #{option.desc}"
    name = "#{name}, default: #{option.default.inspect}" unless option.default.nil?
    name
  end

  result << "  --#{"help, -h".ljust(30)}  # Print this help"
  result.join("\n")
end