Class: Crowbar::Client::App::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/crowbar/client/app/base.rb

Overview

A base class that provides helper for the wrappers

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], local_options = {}, config = {}) ⇒ Crowbar::Client::App::Base

Initialize the Thor command

Parameters:

  • args (Array) (defaults to: [])

    the arguments

  • local_options (Hash) (defaults to: {})

    the local options

  • config (Hash) (defaults to: {})

    the configuration



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/crowbar/client/app/base.rb', line 35

def initialize(args = [], local_options = {}, config = {})
  super

  Config.configure(
    options.slice(
      :alias,
      :username,
      :password,
      :server,
      :verify_ssl,
      :timeout,
      :anonymous,
      :apiversion,
      :debug
    )
  )
end

Class Method Details

A banner that gets displayed on help and error

Parameters:

  • command (String)

    the command for help output

  • namespace (String) (defaults to: nil)

    the namespace for help

  • subcommand (Bool) (defaults to: true)

    the flag if it’s a subcommand

Returns:

  • (String)


142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/crowbar/client/app/base.rb', line 142

def banner(command, namespace = nil, subcommand = true)
  addition = command.formatted_usage(
    self,
    false,
    subcommand
  )

  [
    basename,
    addition
  ].compact.join(" ")
end

.handle_argument_error(command, error, args, arity) ⇒ Object

Properly print an error on invalid command

Parameters:

  • command (String)

    the command that failed

  • error (StandardError)

    the error class

  • args (Array)

    the arguments that failed

  • arity (Integer)

    the number of arguments



129
130
131
132
# File 'lib/crowbar/client/app/base.rb', line 129

def handle_argument_error(command, error, args, arity)
  $stderr.puts("Usage: #{banner(command)}")
  exit(2)
end