Sha256: 035d13c02d7e85f102571b3314dea92e8e5bdbb0b53a44695d505b01c8a206d0

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

#!/usr/bin/env ruby

require 'optparse'

require 'user_agent_parser'
require 'user_agent_parser/cli'

options = {}

optparse = OptionParser.new do|opts|
  opts.on('--family', 'Print family only') do
    options[:family] = true
  end

  opts.on('--name', 'Print name (alias for family) only') do
    options[:family] = true
  end

  opts.on('--version', 'Print version only') do
    options[:version] = true
  end

  opts.on('--major', 'Print major version only') do
    options[:major] = true
  end

  opts.on('--minor', 'Print minor version only') do
    options[:minor] = true
  end

  opts.on('--os', 'Print operating system only') do
    options[:os] = true
  end

  opts.on('--format format',
          'Print output in specified format. The available formatters are:',
          ' - %f: family',
          ' - %n: name (alias for family)',
          ' - %v: version',
          ' - %M: major version',
          ' - %m: minor version',
          ' - %o: operating system'
         ) do |format|
    options[:format] = format
  end

  opts.on('-h', '--help', 'Display this screen') do
    puts opts
    exit
  end
end

optparse.parse!

parser = UserAgentParser::Parser.new

ARGF.each do |line|
  puts UserAgentParser::Cli.new(parser.parse(line), options).run!
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
user_agent_parser-2.4.0 bin/user_agent_parser
user_agent_parser-2.3.2 bin/user_agent_parser
user_agent_parser-2.3.1 bin/user_agent_parser
user_agent_parser-2.3.0 bin/user_agent_parser
user_agent_parser-2.2.0 bin/user_agent_parser