Class: Cf::CLI
- Inherits:
-
Thor
- Object
- Thor
- Cf::CLI
- Includes:
- Config, Thor::Actions
- Defined in:
- lib/cf/cli.rb
Overview
:nodoc: all
Instance Method Summary collapse
Methods included from Config
#config_file, #find_home, #get_api_key, #load_config, #save_config, #set_api_key, #set_target_uri
Instance Method Details
#login ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cf/cli.rb', line 32 def login email = ask("Enter your email:") passwd = ask_password("Enter the password: ") set_target_uri(false) resp = CF::Account.login(email, passwd) if resp.error.blank? and resp.api_key.present? File.open(config_file, 'w') {|f| f.write({ :target_url => CF.api_url, :api_version => CF.api_version, :api_key => resp.api_key }.to_yaml) } say("\nNow you're logged in.\nTo get started, run cf help\n", :green) else say("\n#{resp.error.}\nTry again with valid one.\n", :red) end end |
#output(run_title = nil) ⇒ Object
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 125 126 127 128 129 |
# File 'lib/cf/cli.rb', line 83 def output(run_title=nil) if run_title.present? run_title = run_title.parameterize line_source = Dir.pwd yaml_source = "#{line_source}/line.yml" unless File.exist?(yaml_source) say "The line.yml file does not exist in this directory", :red return end set_target_uri(false) if set_api_key(yaml_source) CF.account_name = CF::Account.info.name if CF.account_name.blank? run = CF::Run.find(run_title) if run.errors.blank? say("Fetching output for run: #{run_title}", :green) if [:station_index].present? # Output for specific station output = CF::Run.output(:title => run_title, :station => [:station_index]) else # Ouput for the whole production run output = CF::Run.final_output(run_title) end res_array = [] output.each do |o| res_array << o.to_hash end csv_str = CSVHash(res_array,res_array.first.keys) FileUtils.mkdir("#{line_source}/output") unless Dir.exist?("#{line_source}/output") csv_file_name = "#{line_source}/output/#{run_title}-#{Time.now.strftime("%e %b %Y %H:%m-%S%p").parameterize}.csv" File.open(csv_file_name, 'w') {|f| f.write(csv_str) } say("Output saved at #{csv_file_name}\n", :yellow) else say("Error: #{run.errors.inspect}") end else say("\nAPI key missing in line.yml file\n") end else say("\nThe run title must be provided to get the output.", :red) say("\te.g. cf output my-run-title\n", :yellow) end end |