module Tabular(T)
#
The Tabular library.
Extended modules
Tabular
Class methods#
.install!(args = ARGV, *, program : String = PROGRAM_NAME, command = Tabular.prompt)#
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— For malformed CLI arguments.Error::Support— If shell is unsupported.
.install?(arg = ARGV, *, prompt = "completion")#
Return true and shift, if the first element in args is the prompt. to install a completion script.
.prompt=(value : String)#
Set the name of the CLI argument that will prompt completions.
.prompt?(args = ARGV)#
Return true and shift, if the first element in args is the Tabular.prompt.
Methods#
#form(words : Array(String) = ARGV, &) : Bool#
Define the set of Tablets and an optional 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
Macros#
define#
Define a completer as an instance method, name, with &block as the form:
class MyClass
Tabular.define my_completer do
option "--help"
command "sub_cmd1"
command "sub_cmd2"
end
end
class MyClass
def my_completer(words : String) : Bool
Tabular.form words do
option "--help"
command "sub_cmd1"
command "sub_cmd2"
end
end
end
installer(name)#
Define a #relay completer, name, as an instance method:
class MyClass
Tabular.installer my_installer
end
class MyClass
def my_installer(words : String) : Bool
Tabular::Fragments.install words
end
end
relayer(name)#
Define a #relay completer as an instance method, name:
class MyClass
Tabular.relay my_completer
end
class MyClass
def my_completer(words : String) : Bool
Tabular.form words do relay end
end
end