Class: Toys::StandardCLI

Inherits:
CLI
  • Object
show all
Defined in:
lib/toys/standard_cli.rb

Overview

Subclass of Toys::CLI configured for the behavior of the standard Toys executable. Specifically, this subclass:

  • Configures the standard names of files and directories, such as the .toys.rb file for an "index" tool, and the .data and .lib directory names.
  • Configures default descriptions for the root tool.
  • Configures a default error handler and logger that provide ANSI-colored formatted output.
  • Configures a set of middleware that implement online help, verbosity flags, and other features.
  • Provides a set of standard templates for typical project build and maintenance scripts (suh as clean, test, and rubocop).
  • Finds tool definitions in the standard Toys search path.

Constant Summary collapse

TOPLEVEL_TOOL_DIR_NAME =

Standard toys tool directory name.

Returns:

  • (String)
".toys"
TOPLEVEL_TOOL_FILE_NAME =

Standard toys tool file name.

Returns:

  • (String)
".toys.rb"
EXECUTABLE_NAME =

Name of the standard toys executable.

Returns:

  • (String)
"toys"
EXTRA_DELIMITERS =

Delimiter characters recognized.

Returns:

  • (String)
":."
DEFAULT_ROOT_DESC =

Short description for the standard root tool.

Returns:

  • (String)
"Your personal command line tool"
DEFAULT_ROOT_LONG_DESC =

Help text for the standard root tool.

Returns:

  • (String)
"Toys is your personal command line tool. You can write commands using a simple Ruby DSL," \
" and Toys will automatically organize them, parse arguments, and provide documentation." \
" Tools can be global or scoped to specific directories. You can also use Toys instead of" \
" Rake to provide build and maintenance scripts for your projects." \
" For detailed information, see https://dazuma.github.io/toys"
DEFAULT_VERSION_FLAG_DESC =

Short description for the version flag.

Returns:

  • (String)
"Show the version of Toys."
TOYS_PATH_ENV =

Name of the toys path environment variable.

Returns:

  • (String)
"TOYS_PATH"

Instance Attribute Summary

Attributes inherited from CLI

#base_level, #completion, #executable_name, #extra_delimiters, #logger, #logger_factory, #tool_name_splitter

Instance Method Summary collapse

Methods inherited from CLI

#add_config_block, #add_config_path, #add_search_path, #add_search_path_hierarchy, #add_source, #child, default_completion, default_error_handler, default_logger_factory, default_middleware_lookup, default_middleware_stack, default_mixin_lookup, default_template_lookup, #finalize_sources!, #load_tool, #loader, #run, #runner

Constructor Details

#initialize(custom_paths: nil, include_builtins: true, cur_dir: nil, git_cache: nil, gems_util: nil) ⇒ StandardCLI

Create a standard CLI, configured with the appropriate paths and middleware.

Parameters:

  • custom_paths (String, Array<String>) (defaults to: nil) —

    Custom paths to use. If set, the CLI uses only the given paths. If not, the CLI will search for paths from the current directory and global paths.

  • include_builtins (boolean) (defaults to: true) —

    Add the builtin tools. Default is true.

  • cur_dir (String, nil) (defaults to: nil) —

    Starting search directory for sources. Defaults to the current working directory.

  • git_cache (Toys::Utils::GitCache, nil) (defaults to: nil) —

    A custom GitCache instance to use when resolving git sources. Optional. If nil or not specified, uses a process-wide default GitCache.

  • gems_util (Toys::Utils::Gems, nil) (defaults to: nil) —

    A custom Gems utility instance to use when resolving gem sources. Optional. If nil or not specified, uses a process-wide default Gems utility.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/toys/standard_cli.rb', line 91

def initialize(custom_paths: nil,
               include_builtins: true,
               cur_dir: nil,
               git_cache: nil,
               gems_util: nil)
  require "toys/utils/standard_ui"
  ui = Utils::StandardUI.new(
    backtrace_omit_prefixes: ::ENV["TOYS_TRACE"].to_s.empty? ? ::Toys.framework_lib_paths : nil,
    incomplete_backtrace_message: "(Set the TOYS_TRACE envvar to a nonempty value to see the full trace.)"
  )
  super(
    executable_name: EXECUTABLE_NAME,
    toplevel_tool_dir_name: TOPLEVEL_TOOL_DIR_NAME,
    toplevel_tool_file_name: TOPLEVEL_TOOL_FILE_NAME,
    extra_delimiters: EXTRA_DELIMITERS,
    middleware_stack: default_middleware_stack,
    template_lookup: default_template_lookup,
    git_cache: git_cache,
    gems_util: gems_util,
    **ui.cli_args
  )
  if custom_paths
    Array(custom_paths).each { |path| add_source(path) }
  else
    add_current_directory_paths(cur_dir)
  end
  add_builtins if include_builtins
end