Class: GGem::CLI
- Inherits:
-
Object
- Object
- GGem::CLI
- Defined in:
- lib/ggem/cli.rb,
lib/ggem/cli/clirb.rb,
lib/ggem/cli/commands.rb
Defined Under Namespace
Modules: ForceTagOptionCommand, GemspecCommand, GitRepoCommand, NotifyCmdCommand, ValidCommand Classes: BuildCommand, CLIRB, CommandSet, GenerateCommand, InstallCommand, InvalidCommand, PushCommand, ReleaseCommand, TagCommand
Constant Summary collapse
- COMMANDS =
CommandSet.new{ |unknown| InvalidCommand.new(unknown) }.tap do |c| c.add(GenerateCommand, "generate", "g") c.add(BuildCommand, "build", "b") c.add(InstallCommand, "install", "i") c.add(PushCommand, "push", "p") c.add(TagCommand, "tag", "t") c.add(ReleaseCommand, "release", "r") end
- InvalidCommandError =
Class.new(ArgumentError)
- CommandExitError =
Class.new(RuntimeError)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(kernel = nil, stdout = nil, stderr = nil) ⇒ CLI
constructor
A new instance of CLI.
- #run(args) ⇒ Object
Constructor Details
#initialize(kernel = nil, stdout = nil, stderr = nil) ⇒ CLI
Returns a new instance of CLI.
24 25 26 27 28 |
# File 'lib/ggem/cli.rb', line 24 def initialize(kernel = nil, stdout = nil, stderr = nil) @kernel = kernel || Kernel @stdout = stdout || $stdout @stderr = stderr || $stderr end |
Class Method Details
.run(args) ⇒ Object
20 21 22 |
# File 'lib/ggem/cli.rb', line 20 def self.run(args) new.run(args) end |
Instance Method Details
#run(args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ggem/cli.rb', line 30 def run(args) begin cmd_name = args.shift cmd = COMMANDS[cmd_name] cmd.run(args) rescue CLIRB::HelpExit @stdout.puts cmd.help rescue CLIRB::VersionExit @stdout.puts GGem::VERSION rescue CLIRB::Error, ArgumentError, InvalidCommandError => ex display_debug(ex) @stderr.puts "#{ex.}\n\n" @stdout.puts cmd.help @kernel.exit 1 rescue CommandExitError @kernel.exit 1 rescue => ex @stderr.puts "#{ex.class}: #{ex.}" @stderr.puts ex.backtrace.join("\n") @kernel.exit 1 end @kernel.exit 0 end |