Class: BuildSpecRunner::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/build_spec_runner/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ CLI

Create a CLI object, parsing the specified argv, or ARGV if none specified.

Parameters:

  • argv (Array) (defaults to: ARGV)

    array of arguments, defaults to ARGV

See Also:



25
26
27
28
# File 'lib/build_spec_runner/cli.rb', line 25

def initialize argv = ARGV
  @options = {}
  CLI::optparse(@options).parse argv
end

Class Method Details

Banner for the CLI usage.



67
68
69
70
71
72
73
74
# File 'lib/build_spec_runner/cli.rb', line 67

def self.banner
  %|Usage: #{File.basename(__FILE__)} arguments

Run a build spec locally.

Arguments:
  |
end

.mainObject

Create and execute a CLI with the default ARGV



78
79
80
# File 'lib/build_spec_runner/cli.rb', line 78

def self.main
  CLI::new.run
end

.optparse(options) ⇒ OptionParser

Create an OptParse for parsing CLI options

The options are as follows:

  • -h --help — Output help message

  • -p --path PATH — Required argument, path the to the project to run

  • -q --quiet — Silence debug messages.

  • --build_spec_path BUILD_SPEC_PATH — Alternative path for buildspec file, defaults to Runner::DEFAULT_BUILD_SPEC_PATH.

  • --profile — AWS profile of the credentials to provide the container, defaults to the default profile. This cannot be specified at the same time as --no_credentials.

  • --no_credentials — Don’t add AWS credentials to the project’s container. This cannot be specified at the same time as --profile.

  • --image_id IMAGE_ID — Id of alternative docker image to use. This cannot be specified at the same time as --aws_dockerfile_path

  • --aws_dockerfile_path AWS_DOCKERFILE_PATH — Alternative AWS CodeBuild Dockerfile path, defaults to DefaultImages::DEFAULT_DOCKERFILE_PATH. This cannot be specified at the same time as --image_id. See the AWS CodeBuild Docker Images repo for the dockerfiles available through this option.

  • --region REGION_NAME — Name of the AWS region to provide to the container. Will set environment variables to make the container appear like it is in the specified AWS region. Otherwise it defaults to the default AWS region configured in the profile.

Parameters:

  • options (Hash)

    the option hash to populate

Returns:

  • (OptionParser)

    the option parser that parses the described options.



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/build_spec_runner/cli.rb', line 51

def self.optparse options
  OptionParser.new do |opts|
    opts.banner = banner
    self.add_opt_path                opts, options
    self.add_opt_build_spec_path     opts, options
    self.add_opt_quiet               opts, options
    self.add_opt_image_id            opts, options
    self.add_opt_aws_dockerfile_path opts, options
    self.add_opt_profile             opts, options
    self.add_opt_no_credentials      opts, options
    self.add_opt_region              opts, options
  end
end

Instance Method Details

#runObject

Run the CLI object, according to the parsed options.

Raises:

  • (OptionParser::InvalidOption)

See Also:



11
12
13
14
15
16
17
# File 'lib/build_spec_runner/cli.rb', line 11

def run
  source_provider = get_source_provider
  image           = get_image
  raise OptionParser::InvalidOption, "Cannot specify both :profile and :no_credentials" if @options[:profile] && @options[:no_credentials]

  BuildSpecRunner::Runner.run image, source_provider, @options
end