Method: HoneyFormat::BenchmarkCLI#parse_options

Defined in:
lib/honey_format/cli/benchmark_cli.rb

#parse_options(argv:) ⇒ Hash

Parse command line arguments and return options

Parameters:

  • argv (Array<String>)

    the command lines arguments

Returns:

  • (Hash)

    the command line options



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/honey_format/cli/benchmark_cli.rb', line 68

def parse_options(argv:)
  input_path = nil
  benchmark_time = 30
  benchmark_warmup = 5
  lines_multipliers = [1]
  verbose = false

  OptionParser.new do |parser|
    parser.banner = 'Usage: bin/benchmark [file.csv] [options]'
    parser.default_argv = argv

    parser.on('--csv=[file1.csv]', String, 'CSV file(s)') do |value|
      input_path = value
    end

    parser.on('--[no-]verbose', 'Verbose output') do |value|
      verbose = value
    end

    parser.on('--lines-multipliers=[1,10,50]', Array, 'Multiply the rows in the CSV file (default: 1)') do |value|
      lines_multipliers = value.map do |v|
        Integer(v).tap do |int|
          unless int >= 1
            raise(ArgumentError, '--lines-multiplier must be 1 or greater')
          end
        end
      end
    end

    parser.on('--time=[30]', String, 'Benchmark time (default: 30)') do |value|
      benchmark_time = Integer(value)
    end

    parser.on('--warmup=[30]', String, 'Benchmark warmup (default: 30)') do |value|
      benchmark_warmup = Integer(value)
    end

    parser.on('-h', '--help', 'How to use') do
      puts parser
      exit
    end

    # No argument, shows at tail. This will print an options summary.
    parser.on_tail('-h', '--help', 'Show this message') do
      puts parser
      exit
    end
  end.parse!

  {
    input_path: input_path,
    benchmark_time: benchmark_time,
    benchmark_warmup: benchmark_warmup,
    lines_multipliers: lines_multipliers,
    verbose: verbose,
  }
end