module Tabular(T)

Overview

The Tabular library.

Extended Modules

Defined in:

tabular.cr
tabular/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

Macro Summary

Instance Method Summary

Class Method Detail

def self.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][Tabular::Error::Argument] — For malformed CLI arguments.
  • [Error::Support][Tabular::Error::Support] — If shell is unsupported.

[View source]
def self.install?(arg = ARGV, *, prompt = "completion") #

Return true and shift, if the first element in args is the prompt. to install a completion script.


[View source]
def self.prompt : String #

Return the name of the CLI argument that will prompt completions.


[View source]
def self.prompt=(value : String) #

Set the name of the CLI argument that will prompt completions.


[View source]
def self.prompt?(args = ARGV) #

Return true and shift, if the first element in args is the [Tabular.prompt][Tabular.prompt].


[View source]

Macro Detail

macro define(name, &block) #

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

[View source]
macro installer(name) #

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

[View source]
macro relayer(name) #

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

[View source]

Instance Method Detail

def 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:

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

[View source]