Class: Pindo::Command::Appstore::Initconfig

Inherits:
Pindo::Command::Appstore show all
Defined in:
lib/pindo/command/appstore/initconfig.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

command_name, #initialize_options, run, use_cache?

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Initconfig

Returns a new instance of Initconfig.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pindo/command/appstore/initconfig.rb', line 62

def initialize(argv)
    # 首先获取位置参数(向后兼容)
    positional_bundleid = argv.shift_argument

    # 获取 test 标志
    @test_flag = argv.flag?('test', false)

    # 使用 Options 模块初始化参数
    @options = initialize_options(argv)

    # 优先使用选项参数,如果没有则使用位置参数
    @bundle_id = @options[:bundleid] || positional_bundleid

    super
    @additional_args = argv.remainder!
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



51
52
53
# File 'lib/pindo/command/appstore/initconfig.rb', line 51

def self.option_items
    @option_items ||= Pindo::Options::BuildOptions.select(:bundleid)
end

.optionsObject

命令的选项列表



56
57
58
59
60
# File 'lib/pindo/command/appstore/initconfig.rb', line 56

def self.options
    [
        ['--test', '创建测试环境仓库']
    ].concat(option_items.map { |item| item.to_claide_option }).concat(super)
end

Instance Method Details

#runObject



93
94
95
96
97
98
99
100
# File 'lib/pindo/command/appstore/initconfig.rb', line 93

def run
    # 使用 BuildInfoManager 创建配置仓库
    build_info_manager = Pindo::BuildInfoManager.share_instance
    build_info_manager.create_appconfig_with_bundleid(
        bundle_id: @bundle_id,
        test_flag: @test_flag
    )
end

#validate!Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pindo/command/appstore/initconfig.rb', line 79

def validate!
    super

    # 如果没有提供 bundleid,提示用户输入
    if @bundle_id.nil? || @bundle_id.empty?
        require 'highline/import'
        cli = HighLine.new
        say "需要输入仓库名称,默认以 Bundle ID 作为仓库名称"
        @bundle_id = cli.ask('请输入 Bundle ID: ')
    end

    help! '需要提供 Bundle ID' if @bundle_id.nil? || @bundle_id.empty?
end