Class: Hanami::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/cli.rb,
lib/hanami/cli/usage.rb,
lib/hanami/cli/banner.rb,
lib/hanami/cli/errors.rb,
lib/hanami/cli/option.rb,
lib/hanami/cli/parser.rb,
lib/hanami/cli/command.rb,
lib/hanami/cli/version.rb,
lib/hanami/cli/registry.rb,
lib/hanami/cli/program_name.rb,
lib/hanami/cli/command_registry.rb

Overview

General purpose Command Line Interface (CLI) framework for Ruby

Since:

  • 0.1.0

Defined Under Namespace

Modules: Banner, Parser, ProgramName, Registry, Usage Classes: Argument, Command, CommandRegistry, Error, InvalidCallbackError, Option, UnknownCommandError

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

"0.3.0".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry) ⇒ Hanami::CLI

Create a new instance

Parameters:

Since:

  • 0.1.0



40
41
42
# File 'lib/hanami/cli.rb', line 40

def initialize(registry)
  @commands = registry
end

Class Method Details

.command?(command) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if command

Parameters:

  • command (Object)

    the command to check

Returns:

  • (TrueClass, FalseClass)

    true if instance of ‘Hanami::CLI::Command`

Since:

  • 0.1.0



25
26
27
28
29
30
31
32
# File 'lib/hanami/cli.rb', line 25

def self.command?(command)
  case command
  when Class
    command.ancestors.include?(Command)
  else
    command.is_a?(Command)
  end
end

.const_missing(name) ⇒ Object

Since:

  • 0.2.1



38
39
40
41
42
# File 'lib/hanami/cli/errors.rb', line 38

def self.const_missing(name)
  super unless name == :UnkwnownCommandError
  Hanami::Utils::Deprecation.new('UnkwnownCommandError is deprecated, please use UnknownCommandError')
  UnknownCommandError
end

Instance Method Details

#call(arguments: ARGV, out: $stdout) ⇒ Object

Invoke the CLI

Parameters:

  • arguments (Array<string>) (defaults to: ARGV)

    the command line arguments (defaults to ‘ARGV`)

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

    the standard output (defaults to ‘$stdout`)

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hanami/cli.rb', line 50

def call(arguments: ARGV, out: $stdout)
  result = commands.get(arguments)

  if result.found?
    command, args = parse(result, out)

    result.before_callbacks.run(command, args)
    command.call(args)
    result.after_callbacks.run(command, args)
  else
    usage(result, out)
  end
end