Cuprum::Cli

A command-line utility powered by Cuprum that provides tools and utilities for defining command-line tools.

Class: Cuprum::Cli::Files::Generator

Parent Namespace
Cuprum::Cli::Files
Inherited Classes
Cuprum::Command > Object
Extended Modules
Cuprum::Cli::Options::ClassMethods
Included Modules
Cuprum::Cli::Dependencies::StandardIo::Helpers, Cuprum::Cli::Options::Quiet, Cuprum::Cli::Options::Verbose, Plumbum::Consumer, Plumbum::Parameters
Defined In
lib/cuprum/cli/files/generator.rb

Table Of Contents

Overview

Command for generating templated files.

Back To Top

Direct Subclasses

Cuprum::Cli::Files::Generators::RSpecGenerator, Cuprum::Cli::Files::Generators::RubyGenerator

Back To Top

Defined Under Namespace

Classes
AbstractGeneratorError, Output, OutputAlreadyExistsError

Back To Top

Constants

FALSY_VALUES

= Set.new(%w[f false n no]).freeze

Inherited From
Cuprum::Cli::Dependencies::StandardIo::Helpers

String input values that will be mapped to a boolean false.

INTEGER_PATTERN

= /\A-?\d+([\d_,]+\d)?\z/

Inherited From
Cuprum::Cli::Dependencies::StandardIo::Helpers

Pattern matching a valid integer input.

TRUTHY_VALUES

= Set.new(%w[t true y yes]).freeze

Inherited From
Cuprum::Cli::Dependencies::StandardIo::Helpers

String input values that will be mapped to a boolean true.

Back To Top

Class Methods

.abstract => Object

Marks the generator as abstract.

.abstract? => true, false

Returns

.match_file(pattern) => void
.match_file(&block) => void

Overloads

.match_file(pattern) => void

Registers the pattern as a valid match for the generator.

The registered matches are checked when the generator checks whether a file path can be generated by the generator.

  • If the given pattern is a regular expression, the generator will match the pattern against the file path.
  • If the pattern is a string, the generator will check if the file path ends with the pattern string.
Parameters
  • pattern (Regexp, String) — the pattern to register.
Returns
  • (void)
.match_file(&block) => void

Registers the block as a valid match for the generator.

The registered matches are checked when the generator checks whether a file path can be generated by the generator. The given block will be called with the file path and generator options; if the block returns a truthy value, the match check returns true.

Yield Parameters
  • file_path (String) — the input file path provided by the user.
  • options (Hash) — additional options for the generator.
Returns
  • (void)

.matches?(file_path, **options) => true, false

Also known as: match?

Checks if the generator matches the given file path and options.

the given file type, path, and options; otherwise false.

Parameters

Returns

.option(name, aliases: [], default: nil, description: nil, required: false, type: :string, **options) => Object

Inherited From
Cuprum::Cli::Options::ClassMethods

Defines an option for the command class.

Parameters

Options Hash (options)

.option_value(option, value) => void

Inherited From
Cuprum::Cli::Options::ClassMethods

Assigns a predefined option value for the command.

Parameters

Returns

.option_values => Hash{Symbol => Object}

Inherited From
Cuprum::Cli::Options::ClassMethods

Returns

.options => Hash{Symbol => Cuprum::Cli::Option}

Inherited From
Cuprum::Cli::Options::ClassMethods

The defined options, including options defined on ancestor classes.

Returns

.output(path, key: :default, template: nil) => void

Registers an output file for the generator.

The output path parameter is a String that can include format strings, which will be resolved from the options passed to the generator. In addition, the format strings can reference the following parameters derived from the input file_path. The following examples use an input file path of “lib/path/to/file.rb”:

Parameters

Returns

.outputs => Hash{Symbol => Output}

Returns

.resolve_options(**values) => Hash

Inherited From
Cuprum::Cli::Options::ClassMethods

Validates the given option values against the defined class options.

Also applies any default values from the defined options.

Parameters

Returns

Raises

Back To Top

Constructor

#initialize(file_path, **options) => Object

Overloads

#initialize(file_path, **options) => Object
Parameters
  • file_path (String, nil) — the input file path provided by the user.
  • options (Hash) — additional options for the generator.
Options Hash (options)
  • dry_run (true, false) — if true, simulates file generation but does not perform the actual file system operations. Defaults to false.
  • quiet (true, false) — if true, does not print generated file names status to STDOUT. Defaults to false.
  • verbose (true, false) — if true, prints the contents of generated files to STDOUT. Defaults to false.

Returns

Back To Top

Instance Attributes

#file_path => String (readonly)

Returns

#options => Hash (readonly)

Returns

Back To Top

Instance Methods

#ask(prompt = nil, caret: true, format: nil, strip: true, **options) => String, Integer, true, false, nil

Inherited From
Cuprum::Cli::Dependencies::StandardIo::Helpers

Requests an input from the input stream.

Parameters

Options Hash (options)

Returns

#file_parameters => Hash

Returns

#parameters => Hash

Returns

#say(message, newline: true, quiet: false, verbose: false, **options) => nil

Inherited From
Cuprum::Cli::Options::Verbose

Prints a message to the output stream.

Parameters

Options Hash (options)

Returns

#warn(message, **options) => nil

Inherited From
Cuprum::Cli::Dependencies::StandardIo::Helpers

Prints a message to the error stream.

Parameters

Options Hash (options)

Returns

Back To Top


Back to Documentation | Reference | Cuprum | Cuprum::Cli | Cuprum::Cli::Files