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/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, Option

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

"0.1.0.beta1".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry) ⇒ Hanami::CLI

Create a new instance

Parameters:

Since:

  • 0.1.0


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

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


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

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

Instance Method Details

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

Invoke the CLI

Parameters:

  • arguments (Array<string>)

    the command line arguments (defaults to `ARGV`)

  • out (IO)

    the standard output (defaults to `$stdout`)

Since:

  • 0.1.0


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

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

  if result.found?
    command, args = parse(result, out)
    command.call(args)
  else
    usage(result, out)
  end
end