Class: Flow::Cli::Commands::Remote
- Inherits:
-
Thor
- Object
- Thor
- Flow::Cli::Commands::Remote
- Defined in:
- lib/flow/cli/commands/remote.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Remote
constructor
A new instance of Remote.
- #list_p12s ⇒ Object
- #list_provisions ⇒ Object
- #login ⇒ Object
- #project_init ⇒ Object
- #upload_p12(file_path, password = nil) ⇒ Object
- #upload_provision(file_path) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Remote
Returns a new instance of Remote.
8 9 10 11 12 13 14 15 16 |
# File 'lib/flow/cli/commands/remote.rb', line 8 def initialize(*args) super(*args) @prompt = TTY::Prompt.new @pastel = Pastel.new @error = @pastel.red.bold.detach @warning = @pastel.yellow.detach @db_manager = Utils::DbManager @api_manager = Utils::FlowApiManager.load_from_db end |
Instance Method Details
#list_p12s ⇒ Object
74 75 76 |
# File 'lib/flow/cli/commands/remote.rb', line 74 def list_p12s puts @api_manager.load_p12s(@db_manager.read_attribute(:current_flow_id)) end |
#list_provisions ⇒ Object
97 98 99 |
# File 'lib/flow/cli/commands/remote.rb', line 97 def list_provisions puts @api_manager.load_provisions(@db_manager.read_attribute(:current_flow_id)) end |
#login ⇒ Object
19 20 21 22 23 24 |
# File 'lib/flow/cli/commands/remote.rb', line 19 def login email = @prompt.ask("email?") password = @prompt.mask("password?") Utils::FlowApiManager.login(email, password) puts "login success" end |
#project_init ⇒ Object
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/flow/cli/commands/remote.rb', line 27 def project_init projects = @api_manager.fetch_projects begin file_origin = `git remote -v`.to_s.match("git.*.git").first rescue puts @warning.call "read git origin fail..." end dict = {} dict = Hash[projects.map { |p| [p[:name].to_s, p[:id]] }] current_project_id = @prompt.select("Choose your project?", dict) @db_manager.save_attribute(:current_project_id, current_project_id) flows = @api_manager.fetch_flows(current_project_id) current_flow_id = if flows.count == 1 flows.first[:id] else dict = {} flows.each { |p| dict[(p[:name]).to_s] = p[:id] } @prompt.select("Choose your flow?", dict) end @db_manager.save_attribute(:current_flow_id, current_flow_id) puts "project_id = #{current_project_id}, flow_id = #{current_flow_id}. saved this info..." end |
#upload_p12(file_path, password = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/flow/cli/commands/remote.rb', line 56 def upload_p12(file_path, password = nil) basename = File.basename file_path project_init unless @db_manager.read_attribute(:current_flow_id) api_p12s = @api_manager.load_p12s(@db_manager.read_attribute(:current_flow_id)) old_p12 = api_p12s.find { |p12| p12[:filename] == basename } unless old_p12.nil? if @prompt.yes? "found a same name file, override?" @api_manager.delete_p12(old_p12[:id], @db_manager.read_attribute(:current_flow_id)) else return puts "canceled.." end end @api_manager.upload_p12(@db_manager.read_attribute(:current_flow_id), file_path, password) puts "uploaded." end |
#upload_provision(file_path) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/flow/cli/commands/remote.rb', line 79 def upload_provision(file_path) basename = File.basename file_path project_init unless @db_manager.read_attribute(:current_flow_id) api_provisions = @api_manager.load_provisions(@db_manager.read_attribute(:current_flow_id)) old_provision = api_provisions.find { |provision| provision[:filename] == basename } unless old_provision.nil? if @prompt.yes? "found a same name file, override?" @api_manager.delete_provision(old_provision[:id], @db_manager.read_attribute(:current_flow_id)) else return puts "canceled.." end end @api_manager.upload_provision(@db_manager.read_attribute(:current_flow_id), file_path) puts "uploaded." end |