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/dependencies.rb,
lib/vanagon/cli/build_host_info.rb,
lib/vanagon/cli/build_requirements.rb

Defined Under Namespace

Classes: Build, BuildHostInfo, BuildRequirements, Completion, Dependencies, 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
      dependencies        write json file to STDOUT that shows all required gems for a given project and platform
      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



95
96
97
# File 'lib/vanagon/cli.rb', line 95

def options_translate(docopt_options)
  docopt_options
end

#options_validate(options) ⇒ Object

Do validation of options



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

def options_validate(options)
  options
end

#parse(argv) ⇒ Object

rubocop:disable Metrics/AbcSize



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
80
81
82
83
# File 'lib/vanagon/cli.rb', line 45

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 'dependencies'
    @sub_parser = Vanagon::CLI::Dependencies.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



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

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