module Toys
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.
This module contains the command line framework underlying Toys
. It can be used to create command line executables using the Toys
DSL
and classes.
Constants
- CORE_LIB_PATH
@private
- CORE_VERSION
@private deprecated
Attributes
Path to the executable. This can, for example, be invoked to run a subtool in a clean environment.
@return [String] if there is an executable @return [nil] if there is no such executable
Public Class Methods
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 {Toys::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
@param name [String] Name of the tool. Defaults to a name inferred from the
class name. (See {Toys::Tool}.)
@param base [Class] Use this tool class as the base class, and inherit helper
methods from it.
@param args [String,Class] Any string-valued positional argument is
interpreted as the name. Any class-valued positional argument is interpreted as the base class.
# File lib/toys/dsl/base.rb, line 28 def Toys.Tool(*args, name: nil, base: nil) # rubocop:disable Naming/MethodName args.each do |arg| case arg when ::Class raise ::ArgumentError, "Both base keyword argument and class-valud argument received" if base base = arg when ::String, ::Symbol raise ::ArgumentError, "Both name keyword argument and string-valud argument received" if name name = arg else raise ::ArgumentError, "Unrecognized argument: #{arg}" end end if base && !base.ancestors.include?(::Toys::Context) raise ::ArgumentError, "Base class must itself be a tool" end return base || ::Toys::Tool if name.nil? ::Class.new(base || ::Toys::Context) do base_class = self define_singleton_method(:inherited) do |tool_class| ::Toys::DSL::Internal.configure_class(tool_class, base_class == self ? name.to_s : nil) super(tool_class) ::Toys::DSL::Internal.setup_class_dsl(tool_class) end end end