Module: Get

Defined in:
lib/get.rb,
lib/get/version.rb

Overview

frozen_string_literal: true

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'0.7.2'
@@subcommands =
{
  describe: Describe.command,
  commit: Commit.command,
  init: Init.command,
  license: License.command,
  complete: Complete.command,
  changelog: Changelog.command,
  tree: Tree.command,
}
@@option_parser =
Optimist::Parser.new do
  subcommand_max_length = @@subcommands.keys.map { |k| k.to_s.length }.max
  usage '-h|-v|(<subcommand> [<subcommand-options])'
  synopsis "    Subcommands:\n    \#{@@subcommands.keys.map { |k| \"  \#{k.to_s.ljust(subcommand_max_length)} => \#{@@subcommands[k].description}\" }.join(\"\\n\")}\n  SUBCOMMANDS\n  version \"Get version: \#{Get::VERSION}\"\n  educate_on_error\n  stop_on @@subcommands.keys.map(&:to_s)\nend\n" unless @@subcommands.empty?

Class Method Summary collapse

Class Method Details

.error(message) ⇒ Object



70
71
72
73
74
# File 'lib/get.rb', line 70

def self.error(message)
  Common.error message do
    @@option_parser.educate
  end
end

.mainObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/get.rb', line 57

def self.main
  @options = Optimist.with_standard_exception_handling(@@option_parser) do
    @@option_parser.parse
  end
  error 'No command or option specified' if ARGV.empty?
  command = ARGV.shift.to_sym
  if @@subcommands.include?(command)
    @@subcommands[command].action.call
  else
    error "Unknown subcommand '#{command}'"
  end
end