abstract class Marten::CLI::Manage::Command::Base
- Marten::CLI::Manage::Command::Base
- Reference
- Object
Overview
Management abstract command.
This class should be subclassed in order to implement per-app management commands. Subclasses will be
automatically registered to the management commands registry, and they will be made available through the
manage
CLI.
Included Modules
Direct Known Subclasses
- Marten::CLI::Manage::Command::ClearSessions
- Marten::CLI::Manage::Command::CollectAssets
- Marten::CLI::Manage::Command::Gen
- Marten::CLI::Manage::Command::GenMigrations
- Marten::CLI::Manage::Command::ListMigrations
- Marten::CLI::Manage::Command::Migrate
- Marten::CLI::Manage::Command::New
- Marten::CLI::Manage::Command::Play
- Marten::CLI::Manage::Command::ResetMigrations
- Marten::CLI::Manage::Command::Routes
- Marten::CLI::Manage::Command::Serve
- Marten::CLI::Manage::Command::Version
Defined in:
marten/cli/manage/command/base.crConstructors
Class Method Summary
-
.command_aliases
Returns the aliases of the command.
-
.command_aliases(*aliases : String | Symbol)
Allows to configure aliases for the command.
-
.command_name(name : String | Symbol)
Allows to set the name of the command.
-
.command_name
Returns the name of the considered command.
-
.help(help : String)
Allows to set the help description of the command.
-
.help
Returns the help description of the command.
Instance Method Summary
-
#handle : Int32
Setups the command and runs it.
-
#handle! : Nil
Setups the command and runs it.
-
#on_argument(name : String | Symbol, description : String, &block : String -> )
Allows to configure a specific command argument.
-
#on_invalid_option(&block : String -> )
Allows to configure a proc to call when invalid options are encountered.
-
#on_option(short_flag : String | Symbol, long_flag : String | Symbol, description : String, &block : String -> )
Allows to configure a specific command option.
-
#on_option(flag : String | Symbol, description : String, &block : String -> )
Allows to configure a specific command option.
-
#on_option_with_arg(short_flag : String | Symbol, long_flag : String | Symbol, arg : String | Symbol, description : String, &block : String -> )
Allows to configure a specific command option with an associated argument.
-
#on_option_with_arg(flag : String | Symbol, arg : String | Symbol, description : String, &block : String -> )
Allows to configure a specific command option with an associated argument.
-
#on_unknown_argument(name : String | Symbol, description : String | Nil = nil, &block : String -> )
Allows to configure a proc to call when unknown arguments are encountered.
-
#on_unknown_argument(&block : String -> )
Allows to configure a proc to call when unknown arguments are encountered.
-
#print(msg, ending = "\n")
Allows to print a message to the output file descriptor.
-
#print_error(msg)
Allows to print a message to the error file descriptor.
-
#print_error_and_exit(msg, exit_code = 1)
Allows to print a message to the error file descriptor and to exit the execution of the command.
-
#run
Runs the command.
-
#setup
Setups the command.
-
#show_usage
Shows the command usage.
-
#stderr : IO
Returns the
IO
object that should be used by the command as the main error file descriptor. -
#stdin : IO
Returns the
IO
object that should be used by the command as the main input file descriptor. -
#stdout : IO
Returns the
IO
object that should be used by the command as the main output file descriptor. -
#style(msg, fore = nil, back = nil, mode = nil)
Allows to apply a style to a specific text value.
Constructor Detail
Class Method Detail
Allows to set the name of the command.
The value set using this method will be used by users when they invoke the command through the use of the
manage
CLI.
Instance Method Detail
Setups the command and runs it.
This method will call the #setup
method, configure the arguments / options parser and then execute the
command through the use of the #run
method. If the execution of the command produces an Errors::Exit
exception (because the exit_raises
option was set to true
at initialization time), then the exception
will be caught and the method will return the exit code.
Setups the command and runs it.
This method will call the #setup
method, configure the arguments / options parser and then execute the
command through the use of the #run
method. Note this method won't silence Errors::Exit
exceptions if
the exit_raises
option was set to true
at initialization time.
Allows to configure a specific command argument.
This method will configure a command argument. It expects a name, a description, and it yields a block to let the command properly assign the argument value to the command object:
class MyCommand < Marten::CLI::Command
def setup
on_argument(:arg, "The name of the argument") do |value|
@arg_var = value
end
end
end
Allows to configure a proc to call when invalid options are encountered.
This method will confiugure a proc to call when invalid options are encountered. The proc will be called for each invalid option, and it will receive the option flag as the first argument.
Allows to configure a specific command option.
This method will configure a command option (eg. --option
). It expects a flag name, a short flag name, a
description, and it yields a block to let the command properly assign the option value to the command
object:
class MyCommand < Marten::CLI::Command
def setup
on_option("o", "option", "The name of the option") do
@option_var = true
end
end
end
Note that the --
must not be included in the option name.
Allows to configure a specific command option.
This method will configure a command option (eg. --option
). It expects a flag name, a description, and it
yields a block to let the command properly assign the option value to the command object:
class MyCommand < Marten::CLI::Command
def setup
on_option(:option, "The name of the option") do
@option_var = true
end
end
end
Note that the --
must not be included in the option name.
Allows to configure a specific command option with an associated argument.
This method will configure a command option (eg. --option
) and an associated argument. It expects a flag
name, a short flag name, an argument name, a description, and it yields a block to let the command properly
assign the option value to the command object:
class MyCommand < Marten::CLI::Command
def setup
on_option_with_arg("o", "option", "arg", "The name of the option") do |arg|
@arg = arg
end
end
end
Note that the --
must not be included in the option name.
Allows to configure a specific command option with an associated argument.
This method will configure a command option (eg. --option
) and an associated argument. It expects a flag
name, an argument name, a description, and it yields a block to let the command properly assign the option
value to the command object:
class MyCommand < Marten::CLI::Command
def setup
on_option_with_arg(:option, :arg, "The name of the option") do |arg|
@arg = arg
end
end
end
Note that the --
must not be included in the option name.
Allows to configure a proc to call when unknown arguments are encountered.
This method will configure a proc to call when unknown arguments are encountered. The proc will be called for each unknown argument, and it will receive the argument value as the first argument. Additionally, this method allows to specify the name of the unknown arguments (which will be used in the help message) and an optional description.
Allows to configure a proc to call when unknown arguments are encountered.
This method will configure a proc to call when unknown arguments are encountered. The proc will be called for each unknown argument, and it will receive the argument value as the first argument.
Allows to print a message to the output file descriptor.
This method will print a textual value to the output file descriptor, and it allows to optionally specify the ending character (which defaults to a newline):
print("This is a message")
print("This is a message without newline", ending = "")
Allows to print a message to the error file descriptor and to exit the execution of the command.
The code used to exit the execution of the command can be specified using the exit_code
argument (defaults
to 1
).
Runs the command.
This method should be overridden by subclasses in order to implement the execution logic of the considered command.
Setups the command.
This method should be overridden by subclasses in order to configure the command arguments and options
through the use of the #on_argument
and #on_option
methods.
Shows the command usage.
This method is called when the help option is specified by the user. It will print the command usage to the output file descriptor by default.
Returns the IO
object that should be used by the command as the main error file descriptor.
Returns the IO
object that should be used by the command as the main input file descriptor.
Returns the IO
object that should be used by the command as the main output file descriptor.
Allows to apply a style to a specific text value.
This method can be used to apply fore
, back
, and mode
styles to a specific text values. This method is
likely to be used in conjunction with the #print
method when outputting messages:
print(style("This is a text", fore: :light_blue, back: :green, mode: :bold))