#
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
#
# All Rights Reserved
#

require "/opt/opscode/embedded/service/omnibus-ctl/osc_upgrade"
require 'optparse'
require 'ostruct'

add_command "chef12-upgrade-upload", "Upload transformed Chef 11 data to a Chef 12 server.", 2 do

    def parse(args)
      @options = OpenStruct.new

      # Define defaults
      @options.chef_server_url = "https://localhost"
      @options.upload_threads = 10

      opt_parser = OptionParser.new do |opts|
        opts.banner = "Usage: private-chef-ctl chef12-upgrade-upload [options]"

        opts.on("-t", "--transformed-data-dir [directory]", "Directory where data for upload to the Chef 12 server is located (Will ask interactively if not passed)") do |ec_dir|
          @options.ec_data_dir = ec_dir
        end

        opts.on("-c", "--chef-server-url [url]", String, "The url of the Chef 12 server.  Defaults to #{@options.chef_server_url}") do |u|
          @options.chef_server_url = u
        end

        opts.on("-u", "--upload-threads [number]", Integer, "The number of threads to use when migrating cookbooks to the new server. Defaults to #{@options.upload_threads}") do |n|
          @options.upload_threads = n
        end

        opts.on("-h", "--help", "Show this message") do
          puts opts
          exit
        end
      end

      opt_parser.parse!(args)
    end

  ### Start script ###

  parse(ARGV)

  ec_data_dir = @options.ec_data_dir || ask("Location of data to upload to Chef 12 server?")

  osc_upgrade = OscUpgrade.new(@options, self)
  osc_upgrade.upload_transformed_data(ec_data_dir)

end

Add a Chef 12 upgrade upload ctl command.
Add a Chef 12 upgrade upload ctl command.

This command will take Chef 12 ready data and upload it to a
Chef 12 server
