Class: Flow::Cli::Commands::Remote

Inherits:
Thor
  • Object
show all
Defined in:
lib/flow/cli/commands/remote.rb

Instance Method Summary collapse

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_p12sObject



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_provisionsObject



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

#loginObject



19
20
21
22
23
24
# File 'lib/flow/cli/commands/remote.rb', line 19

def 
  email = @prompt.ask("email?")
  password = @prompt.mask("password?")
  Utils::FlowApiManager.(email, password)
  puts "login success"
end

#project_initObject



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