Module: TreasureData::Command::Options

Included in:
TreasureData::Command
Defined in:
lib/td/command/options.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.write_format_option(op) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/td/command/options.rb', line 55

def write_format_option(op)
  op.on('-f', '--format FORMAT', 'format of the result to write to the file (tsv, csv, json, msgpack, and msgpack.gz)') {|s|
    unless ['tsv', 'csv', 'json', 'msgpack', 'msgpack.gz'].include?(s)
      raise "Unknown format #{s.dump}. Supported formats are: tsv, csv, json, msgpack, and msgpack.gz"
    end

    yield(s)
  }
end

Instance Method Details

#job_show_options(op) ⇒ Object



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
# File 'lib/td/command/options.rb', line 5

def job_show_options(op)
  opts = {}
  opts[:verbose] = nil
  opts[:wait] = false
  opts[:output] = nil
  opts[:format] = nil
  opts[:render_opts] = {:header => false}
  opts[:limit] = nil
  opts[:exclude] = false

  op.on('-v', '--verbose', 'show logs', TrueClass) {|b|
    opts[:verbose] = b
  }
  op.on('-w', '--wait', 'wait for finishing the job', TrueClass) {|b|
    opts[:wait] = b
  }
  op.on('-G', '--vertical', 'use vertical table to show results', TrueClass) {|b|
    opts[:render_opts][:vertical] = b
  }
  op.on('-o', '--output PATH', 'write result to the file') {|s|
    unless Dir.exist?(File.dirname(s))
      s = File.expand_path(s)
    end
    opts[:output] = s
    opts[:format] ||= 'tsv'
  }
  op.on('-l', '--limit ROWS', 'limit the number of result rows shown when not outputting to file') {|s|
    unless s.to_i > 0
      raise "Invalid limit number. Must be a positive integer"
    end
    opts[:limit] = s.to_i
  }
  op.on('-c', '--column-header', 'output of the columns\' header when the schema is available',
                                 '  for the table (only applies to tsv and csv formats)', TrueClass) {|b|
    opts[:render_opts][:header] = b;
  }
  op.on('-x', '--exclude', 'do not automatically retrieve the job result', TrueClass) {|b|
    opts[:exclude] = b
  }

  op.on('--null STRING', "null expression in csv or tsv") {|s|
    opts[:render_opts][:null_expr] = s.to_s
  }

  write_format_option(op) {|s| opts[:format] = s }

  # CAUTION: this opts is filled by op.cmd_parse
  opts
end