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 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.
86 87 88 89 90 91 92 93 |
# File 'lib/twigg/command.rb', line 86 def initialize(*args) Config.config # ensure `-c`/`--config` option is applied consume_option(%w[-c --config], args) # ensure consumed @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.
103 104 105 |
# File 'lib/twigg/command.rb', line 103 def run raise NotImplementedError end |
#run! ⇒ Object
Run and then die.
96 97 98 99 |
# File 'lib/twigg/command.rb', line 96 def run! run die end |