Class: Toys::StandardMiddleware::ShowRootVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/standard_middleware/show_root_version.rb

Overview

A middleware that displays a version string for the root tool if the --version flag is given.

Constant Summary collapse

DEFAULT_VERSION_FLAGS =

Default version flags

Returns:

  • (Array<String>)
["--version"].freeze
DEFAULT_VERSION_FLAG_DESC =

Default description for the version flags

Returns:

  • (String)
"Display the version"
SHOW_VERSION_KEY =

Key set when the version flag is present

Returns:

  • (Object)
Object.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(version_string: nil, version_flags: DEFAULT_VERSION_FLAGS, version_flag_desc: DEFAULT_VERSION_FLAG_DESC, stream: $stdout) ⇒ ShowRootVersion

Create a ShowVersion middleware

Parameters:

  • version_string (String) (defaults to: nil)

    The string that should be displayed.

  • version_flags (Array<String>) (defaults to: DEFAULT_VERSION_FLAGS)

    A list of flags that should trigger displaying the version. Default is DEFAULT_VERSION_FLAGS.

  • stream (IO) (defaults to: $stdout)

    Output stream to write to. Default is stdout.



37
38
39
40
41
42
43
44
45
# File 'lib/toys/standard_middleware/show_root_version.rb', line 37

def initialize(version_string: nil,
               version_flags: DEFAULT_VERSION_FLAGS,
               version_flag_desc: DEFAULT_VERSION_FLAG_DESC,
               stream: $stdout)
  @version_string = version_string
  @version_flags = version_flags
  @version_flag_desc = version_flag_desc
  @output = stream
end