Sha256: 54e519942b7a1aef9ea1d579014c8f55df9f092b439a21ca585ef4bb4cf844f1

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 KB

Contents

module GLI
  module Commands
    module HelpModules
      # Handles wrapping text
      class ArgNameFormatter
        def format(arguments_description,arguments_options,arguments)
          # Select which format to use: argname or arguments
          # Priority to old way: argname
          desc = format_argname(arguments_description, arguments_options)
          desc = format_arguments(arguments) if desc.strip == ''
          desc
        end

        def format_arguments(arguments)
          return '' if arguments.empty?
          desc = ""

          # Go through the arguments, building the description string
          arguments.each do |arg|
            arg_desc = "#{arg.name}"
            if arg.optional?
              arg_desc = "[#{arg_desc}]"
            end
            if arg.multiple?
              arg_desc = "#{arg_desc}..."
            end
            desc = desc + " " + arg_desc
          end

          desc
        end

        def format_argname(arguments_description,arguments_options)
          return '' if String(arguments_description).strip == ''
          desc = arguments_description
          if arguments_options.include? :optional
            desc = "[#{desc}]"
          end
          if arguments_options.include? :multiple
            desc = "#{desc}..."
          end
          " " + desc
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gli-2.22.1 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.22.0 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.21.5 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.21.4 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.21.3 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.21.2 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.21.1 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.21.0 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.20.1 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.20.0 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.19.2 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.19.1 lib/gli/commands/help_modules/arg_name_formatter.rb
gli-2.19.0 lib/gli/commands/help_modules/arg_name_formatter.rb