Skip to content

class Tabular::Habit
inherits Reference #

A class that manages the formation of a set of Tablets within the block of Tabular.form.

Methods#

#argument(choices : Array(String), help : String = "", directives : Directable | Nil = nil)#

Create a Argument-flavoured Tablet.

  • choices: A set of possible values for the argument. If empty?, any value is accepted.
  • help: See Tablet#help.
  • directives: See Directive.
View source

#argument(*choice, help = "", directives : Directable | Nil = nil)#

Create a Argument-flavoured Tablet.

  • choice: Any number of possible values for the argument. If empty?, any value is accepted.
  • help: See Tablet#help.
  • directives: See Directive.
View source

#command(name : String, aliases : Array(String) = [] of String, help = "", directives : Directable | Nil = nil)#

Create a Command-flavoured Tablet.

View source

#command(name : String, *aliases, help = "", directives : Tabular::Directable | Nil = nil)#

Create a Command-flavoured Tablet.

View source

#command(name : String, aliases : Array(String) = [] of String, help = "", directives : Directable | Nil = nil#

Create a Command-flavoured Tablet along with its nested formation:

Tabular.form do
  command "cmd1", help: "command with dispatched completions"

  command "cmd2", help: "command with inline completions" do
    option "--file", "-f" { argument }
    option "--debug"
    command "sub1"
    command "arg2_choice1", "arg2_choice2"
  end

  # will never trigger on `cmd2`
  dispatch do |command|
    Command1.complete if command.name == "cmd1"
  end
end
View source

#command(name : String, *aliases, help = "", directives : Tabular::Directable | Nil = nil#

Create a Command-flavoured Tablet along with its nested formation:

Tabular.form do
  command "cmd1", help: "command with dispatched completions"

  command "cmd2", help: "command with inline completions" do
    option "--file", "-f" { argument }
    option "--debug"
    command "sub1"
    command "arg2_choice1", "arg2_choice2"
  end

  # will never trigger on `cmd2`
  dispatch do |command|
    Command1.complete if command.name == "cmd1"
  end
end
View source

#delimiters(value : String)#

Specify the global string of characters that may delimit an Option-flavour Tablet.

Tabular.form do
  # Allows for something like `--option=`
  delimiters "="
  # Allows for something like `-option:`
  delimiters ":"
  # Allows for all of the above
  delimiters ":="
end
View source

#delimiters : String#

Return the global string of characters that may delimit an Option-flavour Tablet.

View source

#directives(kind : Kind, value : Directable)#

Sepcify the global Directive for all Tablets of kind.

View source

#directives(kind : Kind) : Directive#

Return the global Directive for all Tablets of kind.

View source

#dispatch#

Yield control back to the CLI with block when a Command is matched:

if Tabular.prompt?
  Tabular.form do
    command "cmd1"
    command "cmd2"

    dispatch do |command|
      # bespoke handling
    end
  end
end
View source

#installer(name = "completion", help = "install [TAB] completions")#

Create a Tablet for the Command that installs completions on your users' shell.

if Tabular.prompt?
  Tabular.form do
    command "cmd1"
    command "cmd2"

    # will complete `setup-tab` and possible params
    installer "setup-tab"

    dispatch do |command|
      # handle `cmd1` & `cmd2`
    end
  end
end
View source

#option(name : String, *aliases, help = "", directives : Directable | Nil = nil, delimiters = Tabular.delimiters, repeatable = false)#

Create a Option-flavoured Tablet.

View source

#option(name : String, *aliases, help = "", delimiters = Tabular.delimiters, repeatable = false#

Create a Option-flavoured Tablet with expected Argument-flavoured Tablet(s):

option "--opt" do
  argument "arg1_choice1", "arg1_choice2", "arg1_choice3"
  argument "arg2_choice1", "arg2_choice2"
end
View source

#relay(words : Array(String) = @words)#

Create a Command that yield completions for words back to the shell:

if Tabular.prompt?
  Tabular.form do
    relay
  end
end

Completions from the point of this Tablet are generated as if the command-line started with the remaining #words. This is useful for sudo-like commands that expect a command prompt to run in a specific context.

View source

#size : Int32#

Returns the number of Tablets in the Habit.

View source

#tablet(kind : Kind, *args, **kwargs)#

Create a Tablet.

View source

#words#

The current set of command-lne arguments in the completion process.

View source