Sha256: 29654a8764ce4c95fbf4e2fd5c553747d3f7755365732b78e6341fc6d4e86a0b

Contents?: true

Size: 942 Bytes

Versions: 4

Compression:

Stored size: 942 Bytes

Contents

require "optparse"

module Brightbox
  module Legacy

    # This is a simple class to take the ARGV array and inject a command in the
    # correct position (after global options but before anything else)
    #
    class ArgsAdjuster
      def initialize(args)
        @args = args
      end

      # @param [String] command The command is insert
      # @return [Array<String>]
      def for_command(command)
        @globals = []

        parser = OptionParser.new do |opts|
          opts.on("-v", "--version") {|op| @globals << "-v" }
          opts.on("-s", "--simple") {|op| @globals << "-s" }
          opts.on("-k", "--insecure") {|op| @globals << "-k" }
          opts.on("-c", "--client CLIENT") {|op| @globals << "-c" << op }
          opts.on("--account ACCOUNT") {|op| @globals << "--account" << op }
        end

        remaining = parser.order(@args)

        [] + @globals + [command] + remaining
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brightbox-cli-1.1.0 lib/brightbox-cli/legacy/args_adjuster.rb
brightbox-cli-1.0.0 lib/brightbox-cli/legacy/args_adjuster.rb
brightbox-cli-1.0.0.rc2 lib/brightbox-cli/legacy/args_adjuster.rb
brightbox-cli-1.0.0.rc1 lib/brightbox-cli/legacy/args_adjuster.rb