Module: Toys::Context::Key

Defined in:
lib/toys/context.rb

Overview

Well-known context keys.

This module is mixed into the runtime context. This means you can reference any of these constants directly from your run method.

Example

tool "my-name" do
  def run
    # TOOL_NAME is available here.
    puts "My name is #{get(TOOL_NAME)}"
  end
end

Constant Summary collapse

ARGS =

Context key for the argument list passed to the current tool. Value is an array of strings.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::ARGS")
CLI =

Context key for the currently running Toys::CLI. You can use the value to reconfigure the framework, for example by calling Toys::CLI#child to run a tool under modified settings. To run a sibling tool without reconfiguring anything, you can also use RUNNER instead. The value could be nil if a CLI is not present.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::CLI")
CONTEXT_DIRECTORY =

Context key for the context directory path. The value is a string.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::CONTEXT_DIRECTORY")
DELEGATED_FROM =

Context key for the context from which the current call was delegated. The value is either another context object, or nil if the current call is not delegated.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::DELEGATED_FROM")
EXECUTABLE_NAME =

Context key for the executable name displayed in help text. The value is a String, provided by the Runner.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::EXECUTABLE_NAME")
LOADER =

Context key for the active Loader object.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::LOADER")
LOGGER =

Context key for the active Logger object.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::LOGGER")
RUNNER =

Context key for the Runner that is running the current tool. You can use the value to run other tools from your tool by calling Runner#run.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::RUNNER")
TOOL =

Context key for the ToolDefinition object being executed.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::TOOL")
TOOL_NAME =

Context key for the full name of the tool being executed. Value is an array of strings.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::TOOL_NAME")
TOOL_SOURCE =

Context key for the SourceInfo describing the source of this tool.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::TOOL_SOURCE")
UNMATCHED_ARGS =

Context key for all unmatched args in order. The value is an array of strings.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::UNMATCHED_ARGS")
UNMATCHED_FLAGS =

Context key for unmatched flags. The value is an array of strings.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::UNMATCHED_FLAGS")
UNMATCHED_POSITIONAL =

Context key for unmatched positional args. The value is an array of strings.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::UNMATCHED_POSITIONAL")
USAGE_ERRORS =

Context key for the list of usage errors raised. The value is an array of ArgParser::UsageError.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::USAGE_ERRORS")
VERBOSITY =

Context key for the verbosity value. The value is an integer defaulting to 0, with higher values meaning more verbose and lower meaning more quiet.

Returns:

  • (Object)
::Toys::UniqueKey.new("Toys::Context::Key::VERBOSITY")