Class: Meer::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/meer/cli.rb

Defined Under Namespace

Classes: ReverseOrder

Constant Summary collapse

JOB_HEADERS =
%w(startTime jobStatus dapJobConfigurationId jobExecutionId progress estimateTime)

Instance Method Summary collapse

Instance Method Details

#csv(workbook, sheet) ⇒ Object



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

def csv(workbook, sheet)
  puts client.workbook_data(workbook, sheet)
end

#jobsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/meer/cli.rb', line 59

def jobs
  data = client.running_jobs
  
  rows = if data.size > 0
    data.select!{|r| r['dapJobConfigurationId'].to_i == options[:workbook] } if options[:workbook]
    data.select!{|r| r['jobExecutionId'].to_i == options[:job] } if options[:job]
    data.sort_by {|r| -r['progress'].to_i }.map { |r| JOB_HEADERS.map{|k| r[k]} }
  else
    []
  end

  puts Terminal::Table.new(headings: JOB_HEADERS, rows: rows)
end

#loginObject



7
8
9
10
11
12
13
# File 'lib/meer/cli.rb', line 7

def 
  user     = ask("username:", default: ENV['USER'])
  password = ask("password:", :echo => false)
  puts
  
  client(user, password).
end

#sheets(workbook_id) ⇒ Object



23
24
25
26
27
# File 'lib/meer/cli.rb', line 23

def sheets(workbook_id)
  client.workbook(workbook_id)['sheets'].each do |sheet|
    puts " - #{sheet['name']}"
  end
end

#start(wb_id) ⇒ Object



50
51
52
# File 'lib/meer/cli.rb', line 50

def start(wb_id)
  puts client.run_workbook(wb_id).to_yaml
end

#table(workbook, sheet) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/meer/cli.rb', line 37

def table(workbook, sheet)
  data = client.workbook_data(workbook, sheet)
  rows = CSV.parse(data, :headers => true).to_a
  headers = rows.slice!(0)
  schema = parse_schema(headers, rows.first)
  
  filter!(schema, rows, options[:filter]) if options[:filter]
  sort!(schema, rows, options[:sort]) if options[:sort]
  
  puts Terminal::Table.new(headings: headers, rows: rows)
end

#workbooksObject



16
17
18
19
20
# File 'lib/meer/cli.rb', line 16

def workbooks 
  client.workbooks.sort_by { |w| w['path'] }.each do |workbook|
    puts " - [#{workbook['id']}] #{workbook['path']}"
  end
end