Module: Pindo::Options::BundleIdSelector

Defined in:
lib/pindo/options/helpers/bundleid_selector.rb

Class Method Summary collapse

Class Method Details

.load_deploy_bundleidsObject

加载发布环境的 Bundle ID 列表



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 77

def self.load_deploy_bundleids
  bundleids = []

  # 从配置文件加载
  config_file = File.join(pindo_env_configdir, 'bundleid_config.json')
  if File.exist?(config_file)
    begin
      config = JSON.parse(File.read(config_file))
      bundleids |= config['all_release_bundleid'] if config['all_release_bundleid']
    rescue => e
      puts "加载 bundleid_config.json 失败: #{e.message}"
    end
  end

  bundleids
end

.load_dev_bundleidsObject

加载开发环境的 Bundle ID 列表



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 58

def self.load_dev_bundleids
  bundleids = []

  # 从配置文件加载
  config_file = File.join(pindo_env_configdir, 'bundleid_config.json')
  if File.exist?(config_file)
    begin
      config = JSON.parse(File.read(config_file))
      bundleids |= config['all_dev_bundleid'] if config['all_dev_bundleid']
      bundleids |= config['all_tool_bundleid'] if config['all_tool_bundleid']
    rescue => e
      puts "加载 bundleid_config.json 失败: #{e.message}"
    end
  end

  bundleids
end

.pindo_env_configdirObject

获取 pindo 环境配置目录



95
96
97
98
99
100
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 95

def self.pindo_env_configdir
  require_relative '../../config/pindoconfig'
  Pindoconfig.instance.pindo_env_configdir
rescue
  File.join(Dir.home, '.pindo', 'config')
end

.select_bundleid(build_type) ⇒ String?

选择开发环境的 Bundle ID

Parameters:

  • build_type (String)

    构建类型 (dev/adhoc/release)

Returns:

  • (String, nil)

    选择的 Bundle ID



9
10
11
12
13
14
15
16
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 9

def self.select_bundleid(build_type)
  case build_type
  when 'adhoc', 'release'
    select_deploy_bundleid
  else
    select_dev_bundleid
  end
end

.select_deploy_bundleidString

选择发布环境的 Bundle ID

Returns:

  • (String)

    选择的 Bundle ID



29
30
31
32
33
34
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 29

def self.select_deploy_bundleid
  all_bundleid = load_deploy_bundleids
  return nil if all_bundleid.empty?

  select_from_list(all_bundleid, "发布环境")
end

.select_dev_bundleidString

选择开发环境的 Bundle ID

Returns:

  • (String)

    选择的 Bundle ID



20
21
22
23
24
25
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 20

def self.select_dev_bundleid
  all_bundleid = load_dev_bundleids
  return nil if all_bundleid.empty?

  select_from_list(all_bundleid, "开发环境")
end

.select_from_list(bundleid_list, env_name) ⇒ Object

从列表中选择 Bundle ID



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 39

def self.select_from_list(bundleid_list, env_name)
  cli = HighLine.new
  puts
  puts "可用的Bundle Id如下::"

  bundleid_list.each_with_index do |bundleid, index|
    puts "#{index + 1}. #{bundleid}"
  end

  choice = cli.ask("请选择使用的Bundle Id,请输入选项(1/2/3...):", Integer) do |q|
    q.in = 1..bundleid_list.size
  end

  selected = bundleid_list[choice - 1]
  puts "已选择 #{env_name} Bundle ID: #{selected}\n"
  selected
end