module Tabular(T)
Overview
The Tabular library.
Extended Modules
Defined in:
tabular.crtabular/enums.cr
tabular/exceptions.cr
tabular/fragments.cr
tabular/habit.cr
tabular/installer.cr
tabular/log.cr
tabular/tablet.cr
tabular/version.cr
Class Method Summary
-
.install!(args = ARGV, *, program : String = PROGRAM_NAME, command = Tabular.prompt)
Sends a completion script for the
<shell>specified in args. -
.install?(arg = ARGV, *, prompt = "completion")
Return
trueand shift, if the first element in args is the prompt. -
.prompt : String
Return the name of the CLI argument that will prompt completions.
-
.prompt=(value : String)
Set the name of the CLI argument that will prompt completions.
-
.prompt?(args = ARGV)
Return
trueand shift, if the first element in args is the [Tabular.prompt][Tabular.prompt].
Macro Summary
-
define(name, &block)
Define a completer as an instance method, name, with &block as the [
#form][Tabular.form]: -
installer(name)
Define a [
#relay][Tabular::Fragments#install] completer, name, as an instance method: -
relayer(name)
Define a [
#relay][Tabular::Habit#relay] completer as an instance method, name:
Instance Method Summary
-
#form(words : Array(String) = ARGV, &) : Bool
Define the set of [
Tablets][Tabular::Tablets] and an optional [Habit#dispatch][Tabular::Habit#dispatch] and process the given words sent from the command-line:
Class Method Detail
Sends a completion script for the <shell> specified in args.
- args: A list of user-specified arguments for the installer.
-
<shell>: The shell to install the completions for (supports:bash,fish,zsh).
-
--development <path>: An alternate path to alias the CLI name to.
- program: The name of the CLI program. Best not to set this one.
- command: The subcommand the completion script will call to get completions.
Raises:
- [
Error::Argument][Tabular::Error::Argument] — For malformed CLI arguments. - [
Error::Support][Tabular::Error::Support] — If shell is unsupported.
Return true and shift, if the first element in args is the prompt. to install a completion script.
Return true and shift, if the first element in args is the [Tabular.prompt][Tabular.prompt].
Macro Detail
Define a completer as an instance method, name, with &block as the [#form][Tabular.form]:
class MyClass
Tabular.define my_completer do
option "--help"
command "sub_cmd1"
command "sub_cmd2"
end
end
This is equivalent to:
class MyClass
def my_completer(words : String) : Bool
Tabular.form words do
option "--help"
command "sub_cmd1"
command "sub_cmd2"
end
end
end
Define a [#relay][Tabular::Fragments#install] completer, name, as an instance method:
class MyClass
Tabular.installer my_installer
end
This is equivalent to:
class MyClass
def my_installer(words : String) : Bool
Tabular::Fragments.install words
end
end
Define a [#relay][Tabular::Habit#relay] completer as an instance method, name:
class MyClass
Tabular.relay my_completer
end
This is equivalent to:
class MyClass
def my_completer(words : String) : Bool
Tabular.form words do relay end
end
end
Instance Method Detail
Define the set of [Tablets][Tabular::Tablets] and an optional [Habit#dispatch][Tabular::Habit#dispatch]
and process the given words sent from the command-line:
Tabular.form do
option "--opt1" "-f", help: "a flag parameter"
option "--opt2" "-a", help: "a optiona with argument" { argument }
option "--opt3", help: "a flag with multiple arguments" do
argument "arg1_choice1", "arg1_choice2", "arg1_choice3"
argument "arg2_choice1", "arg2_choice2"
end
command "cmd1", "cmd1_alias", help: "a subcommand"
# An optional handler for command tablets
dispatch do |command|
if command.name == "cmd1"
Subcommand1.complete ARGV
end
end
end