Sha256: 77d6635379163bab54ea66b4a82799efc6a473b55552ca0bc6870731a232c45e

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

require 'getoptlong'

module Rebuild::CLI
  class RbldCreateCommand < Command
    def initialize
      @usage = "[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

6 entries across 6 versions & 1 rubygems

Version Path
rbld-1.3.8 cli/lib/commands/rbld_create.rb
rbld-1.3.7 cli/lib/commands/rbld_create.rb
rbld-1.3.6 cli/lib/commands/rbld_create.rb
rbld-1.3.5 cli/lib/commands/rbld_create.rb
rbld-1.3.4 cli/lib/commands/rbld_create.rb
rbld-1.3.3 cli/lib/commands/rbld_create.rb