Class: Twigg::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Console, Dependency
Includes:
Console
Defined in:
lib/twigg/command.rb,
lib/twigg/command/git.rb,
lib/twigg/command/help.rb,
lib/twigg/command/init.rb,
lib/twigg/command/stats.rb,
lib/twigg/command/git_hub.rb,
lib/twigg/command/russian.rb,
lib/twigg/command/git_host.rb

Direct Known Subclasses

GitHost, Help, Init, Russian, Stats

Defined Under Namespace

Classes: Git, GitHost, GitHub, Help, Init, Russian, Stats

Constant Summary collapse

PUBLIC_SUBCOMMANDS =

Subcommands, in the order they should appear in the help output.

%w[help init app stats gerrit github pivotal git]
EASTER_EGGS =
%w[russian]
SUBCOMMANDS =
PUBLIC_SUBCOMMANDS + EASTER_EGGS

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Command

Returns a new instance of Command.



93
94
95
96
97
98
99
100
101
# File 'lib/twigg/command.rb', line 93

def initialize(*args)
  # the -c/--config option is applied immediately on load (see
  # twigg/lib/twigg.rb); ensure it gets consumed
  consume_option(%w[-c --config], args)

  @debug   = true if args.delete('-d') || args.delete('--debug')
  @verbose = true if args.delete('-v') || args.delete('--verbose')
  @args    = args
end

Class Method Details

.run(subcommand, *args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/twigg/command.rb', line 25

def run(subcommand, *args)
  Help.new('usage').run! unless SUBCOMMANDS.include?(subcommand)

  if args.include?('-h') || args.include?('--help')
    Help.new(subcommand).run
    exit
  end

  begin
    send(subcommand, *args)
  rescue => e
    raise if args.include?('-d') || args.include?('--debug')

    error e.message
    stderr '[run with -d or --debug flag to see full stack trace]'
    die
  end
end

Instance Method Details

#runObject

Abstract implementation of a “run” method; subclasses are expected to override this method.

Raises:

  • (NotImplementedError)


111
112
113
# File 'lib/twigg/command.rb', line 111

def run
  raise NotImplementedError
end

#run!Object

Run and then die.



104
105
106
107
# File 'lib/twigg/command.rb', line 104

def run!
  run
  die
end