Class: Twigg::Command
- Inherits:
-
Object
- Object
- Twigg::Command
- 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
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
-
#initialize(*args) ⇒ Command
constructor
A new instance of Command.
-
#run ⇒ Object
Abstract implementation of a “run” method; subclasses are expected to override this method.
-
#run! ⇒ Object
Run and then die.
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. stderr '[run with -d or --debug flag to see full stack trace]' die end end |
Instance Method Details
#run ⇒ Object
Abstract implementation of a “run” method; subclasses are expected to override this method.
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 |