Class: Vanagon::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/vanagon/cli.rb,
lib/vanagon/cli/list.rb,
lib/vanagon/cli/ship.rb,
lib/vanagon/cli/sign.rb,
lib/vanagon/cli/build.rb,
lib/vanagon/cli/render.rb,
lib/vanagon/cli/inspect.rb,
lib/vanagon/cli/completion.rb,
lib/vanagon/cli/build_host_info.rb,
lib/vanagon/cli/build_requirements.rb

Defined Under Namespace

Classes: Build, BuildHostInfo, BuildRequirements, Completion, Inspect, List, Render, Ship, Sign

Constant Summary collapse

DOCUMENTATION =
<<~DOCOPT.freeze
  Usage:
      vanagon <command> [<args>]...

  Commands are:
      build               build a package given a project and platform
      build_host_info     print information about build hosts
      build_requirements  print external packages required to build project
      completion          outputs path to tab completion script
      inspect             a build dry-run, printing lots of information about the build
      list                shows a list of available projects and platforms
      render              create local versions of packaging artifacts for project
      sign                sign a package
      ship                upload a package to a distribution server
      help                print this help
DOCOPT

Instance Method Summary collapse

Instance Method Details

#options_translate(docopt_options) ⇒ Object

Provide a translation from parsed docopt options to older optparse options



91
92
93
# File 'lib/vanagon/cli.rb', line 91

def options_translate(docopt_options)
  docopt_options
end

#options_validate(options) ⇒ Object

Do validation of options



86
87
88
# File 'lib/vanagon/cli.rb', line 86

def options_validate(options)
  options
end

#parse(argv) ⇒ Object

rubocop:disable Metrics/AbcSize



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vanagon/cli.rb', line 43

def parse(argv) # rubocop:disable Metrics/AbcSize
  parsed_options = parse_options(argv)
  sub_command = parsed_options['<command>']
  sub_argv = parsed_options['<args>']

  case sub_command
  when 'build'
    @sub_parser = Vanagon::CLI::Build.new
  when 'build_host_info'
    @sub_parser = Vanagon::CLI::BuildHostInfo.new
  when 'build_requirements'
    @sub_parser = Vanagon::CLI::BuildRequirements.new
  when 'completion'
    @sub_parser = Vanagon::CLI::Completion.new
  when 'inspect'
    @sub_parser = Vanagon::CLI::Inspect.new
  when 'render'
    @sub_parser = Vanagon::CLI::Render.new
  when 'list'
    @sub_parser = Vanagon::CLI::List.new
  when 'sign'
    @sub_parser = Vanagon::CLI::Sign.new
  when 'ship'
    @sub_parser = Vanagon::CLI::Ship.new
  when 'help'
    puts DOCUMENTATION
    exit 0
  else
    VanagonLogger.error "vanagon: Error: unknown command: \"#{sub_command}\"\n\n#{DOCUMENTATION}"
    exit 1
  end

  raw_options = @sub_parser.parse(sub_argv)
  options = @sub_parser.options_translate(raw_options)
  @sub_parser.options_validate(options)
  return options
end

#run(options) ⇒ Object



81
82
83
# File 'lib/vanagon/cli.rb', line 81

def run(options)
  @sub_parser.run(options)
end