Module: CommandKit::Arguments::ClassMethods

Defined in:
lib/command_kit/arguments.rb

Overview

Defines class-level methods.

Instance Method Summary collapse

Instance Method Details

#argument(name, **kwargs) ⇒ Argument

Defines an argument for the class.

Examples:

Define an argument:

argument :bar, desc: "Bar argument"

Defines an argument with a multi-line description:

argument :bar, desc: [
                       "Line 1 ...",
                       "Line 2 ..."
                     ]

With a custom usage string:

argument :bar, usage: 'BAR',
               desc: "Bar argument"

With a custom type:

argument :bar, desc: "Bar argument"

With a default value:

argument :bar, default: "bar.txt",
               desc: "Bar argument"

An optional argument:

argument :bar, required: true,
               desc: "Bar argument"

A repeating argument:

argument :bar, repeats: true,
               desc: "Bar argument"

Parameters:

  • name (Symbol)

    The name of the argument.

  • kwargs (Hash{Symbol => Object})

    Keyword arguments.

Options Hash (**kwargs):

  • usage (String, nil)

    The usage string for the argument. Defaults to the argument's name.

  • required (Boolean)

    Specifies whether the argument is required or optional.

  • repeats (Boolean)

    Specifies whether the argument can be repeated multiple times.

  • desc (String, Array<String>)

    The description for the argument.

Returns:

  • (Argument)

    The newly defined argument.



161
162
163
# File 'lib/command_kit/arguments.rb', line 161

def argument(name,**kwargs)
  arguments[name] = Argument.new(name,**kwargs)
end

#argumentsHash{Symbol => Argument}

All defined arguments for the class.

Returns:

  • (Hash{Symbol => Argument})

    The defined argument for the class and it's superclass.



99
100
101
102
103
104
105
# File 'lib/command_kit/arguments.rb', line 99

def arguments
  @arguments ||= if superclass.kind_of?(ClassMethods)
                   superclass.arguments.dup
                 else
                   {}
                 end
end