File: user_agent_parser

package info (click to toggle)
ruby-user-agent-parser 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 256 kB
  • sloc: ruby: 374; makefile: 6
file content (60 lines) | stat: -rwxr-xr-x 1,300 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
# frozen_string_literal: true

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