Class: Hanami::CLI

Inherits:
Object
  • Object
show all
Defined in:
gems/gems/hanami-1.3.0/lib/hanami/cli/commands.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/new.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/assets.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/routes.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/server.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/command.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/console.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/drop.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/destroy.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/project.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/version.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/apply.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/create.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/templates.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/console.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/migrate.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/prepare.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/version.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/db/rollback.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/destroy/app.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate/app.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/destroy/model.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/destroy/action.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/destroy/mailer.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate/model.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate/action.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate/mailer.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate/secret.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/assets/precompile.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/destroy/migration.rb,
gems/gems/hanami-1.3.0/lib/hanami/cli/commands/generate/migration.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/usage.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/banner.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/errors.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/option.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/parser.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/command.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/version.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/registry.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/program_name.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli/command_registry.rb,
gems/gems/hanami-cli-0.3.0/lib/hanami/cli.rb

Overview

General purpose Command Line Interface (CLI) framework for Ruby

Since:

  • 0.1.0

Defined Under Namespace

Modules: Registry Classes: Command, Error, InvalidCallbackError, UnknownCommandError

Constant Summary

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

def initialize(registry)
  @commands = registry
end

Class Method Details

.const_missing(name) ⇒ Object

Since:

  • 0.2.1

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

.register(name, command = nil, aliases: [], &blk) ⇒ Object

Register a command to expand Hanami CLI

Examples:

Third party gem

require "hanami/cli/commands"

module Hanami
  module Webpack
    module CLI
      module Commands
        class Generate < Hanami::CLI::Command
          desc "Generate Webpack config"

          def call(*)
            # ...
          end
        end
      end
    end
  end
end

Hanami::CLI.register "generate webpack", Hanami::Webpack::CLI::Commands::Generate

# $ bundle exec hanami generate
# Commands:
#   hanami generate action APP ACTION                    # Generate an action for app
#   hanami generate app APP                              # Generate an app
#   hanami generate mailer MAILER                        # Generate a mailer
#   hanami generate migration MIGRATION                  # Generate a migration
#   hanami generate model MODEL                          # Generate a model
#   hanami generate secret [APP]                         # Generate session secret
#   hanami generate webpack                              # Generate Webpack configuration

Parameters:

  • name (String)

    the command name

  • command (NilClass, Hanami::CLI::Command, Hanami::CLI::Commands::Command) (defaults to: nil)

    the optional command

  • aliases (Array<String>)

    an optional list of aliases

Since:

  • 1.1.0

def self.register(name, command = nil, aliases: [], &blk)
  Commands.register(name, command, aliases: aliases, &blk)
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

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