Class: Meer::CLI
- Inherits:
-
Thor
- Object
- Thor
- Meer::CLI
- 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
- #csv(workbook, sheet) ⇒ Object
- #jobs ⇒ Object
- #login ⇒ Object
- #sheets(workbook_id) ⇒ Object
- #start(wb_id) ⇒ Object
- #table(workbook, sheet) ⇒ Object
- #workbooks ⇒ Object
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 |
#jobs ⇒ Object
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 == [:workbook] } if [:workbook] data.select!{|r| r['jobExecutionId'].to_i == [:job] } if [: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 |
#login ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/meer/cli.rb', line 7 def login user = ask("username:", default: ENV['USER']) password = ask("password:", :echo => false) puts client(user, password).login 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, [:filter]) if [:filter] sort!(schema, rows, [:sort]) if [:sort] puts Terminal::Table.new(headings: headers, rows: rows) end |
#workbooks ⇒ Object
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 |