Module: Toys

Defined in:
core-docs/toys-core.rb,
core-docs/toys/cli.rb,
core-docs/toys/core.rb,
core-docs/toys/flag.rb,
core-docs/toys/mixin.rb,
core-docs/toys/compat.rb,
core-docs/toys/errors.rb,
core-docs/toys/loader.rb,
core-docs/toys/context.rb,
core-docs/toys/acceptor.rb,
core-docs/toys/dsl/base.rb,
core-docs/toys/dsl/flag.rb,
core-docs/toys/dsl/tool.rb,
core-docs/toys/settings.rb,
core-docs/toys/template.rb,
core-docs/toys/utils/xdg.rb,
core-docs/toys/arg_parser.rb,
core-docs/toys/completion.rb,
core-docs/toys/flag_group.rb,
core-docs/toys/middleware.rb,
core-docs/toys/utils/exec.rb,
core-docs/toys/utils/gems.rb,
core-docs/toys/source_info.rb,
core-docs/toys/dsl/internal.rb,
core-docs/toys/module_lookup.rb,
core-docs/toys/dsl/flag_group.rb,
core-docs/toys/positional_arg.rb,
core-docs/toys/utils/terminal.rb,
core-docs/toys/tool_definition.rb,
core-docs/toys/utils/git_cache.rb,
core-docs/toys/utils/help_text.rb,
core-docs/toys/wrappable_string.rb,
core-docs/toys/dsl/positional_arg.rb,
core-docs/toys/standard_mixins/xdg.rb,
core-docs/toys/standard_mixins/exec.rb,
core-docs/toys/standard_mixins/gems.rb,
core-docs/toys/standard_mixins/bundler.rb,
core-docs/toys/utils/completion_engine.rb,
core-docs/toys/standard_mixins/highline.rb,
core-docs/toys/standard_mixins/terminal.rb,
core-docs/toys/standard_mixins/fileutils.rb,
core-docs/toys/standard_mixins/git_cache.rb,
core-docs/toys/standard_middleware/show_help.rb,
core-docs/toys/standard_middleware/apply_config.rb,
core-docs/toys/standard_middleware/show_root_version.rb,
core-docs/toys/standard_middleware/add_verbosity_flags.rb,
core-docs/toys/standard_middleware/handle_usage_errors.rb,
core-docs/toys/standard_middleware/set_default_descriptions.rb,
lib/toys/testing.rb,
lib/toys/version.rb,
lib/toys/standard_cli.rb,
lib/toys/templates/rake.rb,
lib/toys/templates/rdoc.rb,
lib/toys/templates/clean.rb,
lib/toys/templates/rspec.rb,
lib/toys/templates/yardoc.rb,
lib/toys/templates/rubocop.rb,
lib/toys/templates/minitest.rb,
lib/toys/templates/gem_build.rb,
lib/toys.rb

Overview

Toys is a configurable command line tool. Write commands in config files using a simple DSL, and Toys will provide the command line executable and take care of all the details such as argument parsing, online help, and error reporting. Toys is designed for software developers, IT professionals, and other power users who want to write and organize scripts to automate their workflows. It can also be used as a Rake replacement, providing a more natural command line interface for your project's build tasks.

Defined Under Namespace

Modules: Acceptor, Completion, Core, DSL, FlagGroup, InputFile, Middleware, Mixin, StandardMiddleware, StandardMixins, Template, Templates, Testing, Utils Classes: ArgParser, ArgParsingError, CLI, Context, ContextualError, Flag, Loader, LoaderError, ModuleLookup, NotRunnableError, PositionalArg, Settings, SourceInfo, StandardCLI, Tool, ToolDefinition, ToolDefinitionError, WrappableString

Constant Summary collapse

VERSION =

Current version of the Toys command line executable.

Returns:

  • (String)
"0.13.1"
EXECUTABLE_PATH =

Path to the Toys executable.

Returns:

  • (String)

    Absolute path to the executable

  • (nil)

    if the Toys executable is not running.

::ENV["TOYS_BIN_PATH"]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.executable_pathString?

Path to the executable. This can, for example, be invoked to run a subtool in a clean environment.

Returns:

  • (String)

    if there is an executable

  • (nil)

    if there is no such executable



61
62
63
# File 'core-docs/toys-core.rb', line 61

def executable_path
  @executable_path
end

Class Method Details

.Tool(*args, name: nil, base: nil) ⇒ Object

Create a base class for defining a tool with a given name.

This method returns a base class for defining a tool with a given name. This is useful if the naming behavior of Tool is not adequate for your tool.

Example

class FooBar < Toys.Tool("Foo_Bar")
  desc "This is a tool called Foo_Bar"

  def run
    puts "Foo_Bar called"
  end
end

Parameters:

  • name (String) (defaults to: nil)

    Name of the tool. Defaults to a name inferred from the class name. (See Tool.)

  • base (Class) (defaults to: nil)

    Use this tool class as the base class, and inherit helper methods from it.

  • args (String, Class)

    Any string-valued positional argument is interpreted as the name. Any class-valued positional argument is interpreted as the base class.



26
27
28
# File 'core-docs/toys/dsl/base.rb', line 26

def Toys.Tool(*args, name: nil, base: nil)
  # Source available in the toys-core gem
end