def parse_args(arguments=ARGV)
      options = { :attributes => {}, :parameters => {}, :verbose => false }

      parser = Trollop::Parser.new do
        opt :id, "", :type => String, :long => "--identity", :short => "-i"
        opt :name, "", :type => String
        opt :parameter, "", :type => :string, :multi => true, :short => "-p"
        opt :thread, "", :type => String
        opt :json_file, "", :type => String, :short => "-j", :long => "--json"
        opt :tags, "", :type => String, :short => "-r", :long => "--recipient_tags"
        opt :scope, "", :type => String, :default => "all"
        opt :cfg_dir, "", :type => String
        opt :policy, "", :type => String, :short => "-P"
        opt :audit_period, "", :type => :int, :long => "--audit_period"
        opt :timeout, "", :type => :int, :short => "-T", :default => DEFAULT_TIMEOUT
        opt :verbose
        version ""
      end

      parse do
        options.merge!(parser.parse(arguments))
        options.delete(:name) if options[:id]

        if options[:parameter]
          options.delete(:parameter).each do |p|
            name, value = p.split('=', 2)
            if name && value && value.include?(':')
              options[:parameters][name] = value
            else
              fail("Invalid parameter definition '#{p}', should be of the form 'name=type:value'")
            end
          end
        end

        if options[:json_file]
          fail("Invalid JSON filename '#{options[:json_file]}'") unless File.file?(options[:json_file])
          begin
            options[:json] = IO.read(options[:json_file])
          rescue Exception => e
            fail("Invalid JSON content: #{e}")
          end
        end

        options[:tags] = options[:tags].split if options[:tags]

        if options[:scope]
          if options[:scope] == 'single'
            options[:scope] = :any
          elsif options[:scope] == 'all'
            options[:scope] = :all
          else
            fail("Invalid scope definition '#{options[:scope]}', should be either 'single' or 'all'")
          end
        end

        if options[:thread] && (options[:thread] !~ RightScale::AgentConfig.valid_thread_name)
          fail("Invalid thread name #{options[:thread]}", true)
        end

        options
      end
    end
def parse_args(arguments=ARGV)
      options = { :attributes => {}, :parameters => {}, :verbose => false }

      parser = Trollop::Parser.new do
        opt :id, "", :type => String, :long => "--identity", :short => "-i"
        opt :name, "", :type => String
        opt :parameter, "", :type => :string, :multi => true, :short => "-p"
        opt :thread, "", :type => String
        opt :json_file, "", :type => String, :short => "-j", :long => "--json"
        opt :tags, "", :type => String, :short => "-r", :long => "--recipient_tags"
        opt :scope, "", :type => String, :default => "all"
        opt :cfg_dir, "", :type => String
        opt :policy, "", :type => String, :short => "-P"
        opt :audit_period, "", :type => :int, :long => "--audit_period"
        opt :timeout, "", :type => :int, :short => "-T", :default => DEFAULT_TIMEOUT
        opt :verbose
        version ""
      end

      parse do
        options.merge!(parser.parse(arguments))
        options.delete(:name) if options[:id]

        if options[:parameter]
          options.delete(:parameter).each do |p|
            name, value = p.split('=', 2)
            if name && value && value.include?(':')
              options[:parameters][name] = value
            else
              fail("Invalid parameter definition '#{p}', should be of the form 'name=type:value'")
            end
          end
        end

        if options[:json_file]
          fail("Invalid JSON filename '#{options[:json_file]}'") unless File.file?(options[:json_file])
          begin
            options[:json] = IO.read(options[:json_file])
          rescue Exception => e
            fail("Invalid JSON content: #{e}")
          end
        end

        options[:tags] = options[:tags].split if options[:tags]

        if options[:scope]
          if options[:scope] == 'single'
            options[:scope] = :any
          elsif options[:scope] == 'all'
            options[:scope] = :all
          else
            fail("Invalid scope definition '#{options[:scope]}', should be either 'single' or 'all'")
          end
        end

        if options[:thread] && (options[:thread] !~ RightScale::AgentConfig.valid_thread_name)
          fail("Invalid thread name #{options[:thread]}", true)
        end

        options
      end
    end
Create options hash from command line arguments

 === Return
 options(Hash):: Hash of options as defined by the command line