Class: Json2xxx::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/json2xxx/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/json2xxx/cli.rb', line 13

def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  @global_options = config[:shell].base.options
  return unless File.pipe?(STDIN)
  @data = parse_json(STDIN.read)
  @core = Core.new
  if @global_options['fields']
    @data = @core.extract(@data, @global_options['fields'])
  end
  if @global_options['sort']
    @data = @core.sort(@data, @global_options['sort'])
  end
end

Instance Method Details

#backlogObject



59
60
61
# File 'lib/json2xxx/cli.rb', line 59

def backlog
  puts @core.convert_backlog_wiki(@data)
end

#csvObject



44
45
46
# File 'lib/json2xxx/cli.rb', line 44

def csv
  puts @core.convert_csv(@data, ',', options['force_quotes'], options['write_header'])
end

#delimiter(delim) ⇒ Object



30
31
32
# File 'lib/json2xxx/cli.rb', line 30

def delimiter(delim)
  puts @core.convert_csv(@data, delim, options['force_quotes'], options['write_header'])
end

#excelObject



75
76
77
# File 'lib/json2xxx/cli.rb', line 75

def excel
  @core.convert_excel(@data, options['output'])
end

#hashObject



69
70
71
# File 'lib/json2xxx/cli.rb', line 69

def hash
  ap @data, indent: 2, index: false
end

#htmlObject



64
65
66
# File 'lib/json2xxx/cli.rb', line 64

def html
  puts @core.convert_html(@data)
end

#markdownObject



54
55
56
# File 'lib/json2xxx/cli.rb', line 54

def markdown
  puts @core.convert_markdown(@data)
end

#tsvObject



37
38
39
# File 'lib/json2xxx/cli.rb', line 37

def tsv
  puts @core.convert_csv(@data, "\t", options['force_quotes'], options['write_header'])
end

#yamlObject



49
50
51
# File 'lib/json2xxx/cli.rb', line 49

def yaml
  puts YAML.dump(@data)
end