abstract class LuckyTask::Task

Defined in:

lucky_task/task.cr

Instance Method Summary

Macro Summary

Instance Method Detail

abstract def call #

[View source]

Macro Detail

macro arg(arg_name, description, shortcut = nil, optional = false, format = nil, example = nil) #

Creates a method of arg_name that returns the value passed in from the CLI. The CLI arg is specified by the --arg_name=VALUE flag.

  • arg_name : String - The name of the argument
  • description : String - The help text description for this option
  • shorcut : String - An optional short flag (e.g. -a VALUE)
  • optional : Bool - When false, raise exception if this arg is not passed
  • format : Regex - The format you expect the args to match
  • example : String - An example string that matches the given format

[View source]
macro float64(arg_name, description, shortcut = nil, default = nil) #

Creates a method of arg_name where the return value is an Float64. If the flag --arg_name is passed, the result is the value passed, otherwise is set to the specified default, or 0.0 when not specified.

  • arg_name : String - The name of the argument
  • description : String - The help text description for this option
  • shorcut : String - An optional short flag (e.g. -a)
  • default : Float64 - An optional default value (0.0 is default when omittted)

Example: float64 :threshold, "(0.1, 3.14, -5.1, etc.)", shortcut: "-t", default: 2.0


[View source]
macro help_message(help_text) #

Customize your help message with the provided help_text

class KeyGen < LuckyTask::Task
  summary "Generate a new key"
  help_message "Call lucky key_gen to generate a new key"

  # other methods, etc.
end

[View source]
macro int32(arg_name, description, shortcut = nil, default = nil) #

Creates a method of arg_name where the return value is an Int32. If the flag --arg_name is passed, the result is the value passed, otherwise is set to the specified default, or 0 when not specified.

  • arg_name : String - The name of the argument
  • description : String - The help text description for this option
  • shorcut : String - An optional short flag (e.g. -a)
  • default : Int32 - An optional default value (0 is default when omittted)

Example: int32 :limit, "limit (1000, 10_000, etc.)", shortcut: "-l", default: 1_000


[View source]
macro name(name_text) #

Renames the task name for CLI use

By default the task name is derived from the full module and class name. However if that task name is not desired, a custom one can be set.

class Dev::Prime < LuckyTask::Task
  # Would be "dev.prime" by default, but we want to set it to "dev.setup":
  task_name "dev.setup"
  summary "Seed the development database with example data"

  # other methods, etc.
end

[View source]
macro positional_arg(arg_name, description, to_end = false, format = nil, example = nil) #

Creates a method of arg_name that returns the value passed in from the CLI. The CLI arg position is based on the order in which positional_arg is specified with the first call being position 0, and so on.

If your arg takes more than one value, you can set to_end to true to capture all args from this position to the end. This will make your arg_name method return Array(String).

  • arg_name : String - The name of the argument
  • description : String - The help text description for this option
  • to_end : Bool - Capture all args from this position to the end.
  • format : Regex - The format you expect the args to match
  • example : String - An example string that matches the given format

[View source]
macro summary(summary_text) #

The general description of what this task does

This is used in the help_text when a help flag is passed to the task through the CLI


[View source]
macro switch(arg_name, description, shortcut = nil) #

Creates a method of arg_name where the return value is boolean. If the flag --arg_name is passed, the value is true.

  • arg_name : String - The name of the argument
  • description : String - The help text description for this option
  • shorcut : String - An optional short flag (e.g. -a)

[View source]