Sha256: b674fca9a33b7fee53a4ca7752c8af8c27d7ed06beb064529f1a293f9ec40a7b

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

require 'getoptlong'

module Rebuild::CLI
  class RbldCreateCommand < Command
    def initialize
      @usage = "create [OPTIONS] [ENVIRONMENT]"
      @description = "Create a new environment"
      @options = [
                  ["-b NAME, --base NAME", "Base image from Docker Hub"],
                  ["-f NAME, --basefile NAME", "Base file"]
                 ]
    end

    def parse_opts(parameters)
      replace_argv( parameters ) do
        opts = GetoptLong.new([ '--base', '-b', GetoptLong::REQUIRED_ARGUMENT ],
                              [ '--basefile', '-f', GetoptLong::REQUIRED_ARGUMENT ])
        base = basefile = nil
        opts.each do |opt, arg|
          case opt
            when '--base'
              base = arg
            when '--basefile'
              basefile = arg
          end
        end

        raise "Exactly one environment base must be specified" \
          if base && basefile

        raise "Environment base not specified" \
          unless base || basefile

        raise "Base file #{basefile} does not exist" \
          if basefile && !File.file?(basefile)

        return base, basefile, ARGV
      end
    end

    def run(parameters)
      base, basefile, parameters = parse_opts( parameters )

      env = Environment.new( parameters[0], force_no_tag: true )
      rbld_log.info("Going to create #{env} from #{base || basefile}")
      engine_api.create!( base, basefile, env )
      rbld_print.progress "Successfully created #{env.full}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rbld-1.3.2 cli/lib/commands/rbld_create.rb
rbld-1.3.1 cli/lib/commands/rbld_create.rb
rbld-1.3.0 cli/lib/commands/rbld_create.rb
rbld-1.2.0 cli/lib/commands/rbld_create.rb
rbld-1.1.0 cli/lib/commands/rbld_create.rb
rbld-1.0.2 cli/lib/commands/rbld_create.rb
rbld-1.0.1 cli/lib/commands/rbld_create.rb
rbld-1.0.0 cli/lib/commands/rbld_create.rb