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.



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

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

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

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

    super
    @additional_args = argv.remainder!
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



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

def self.option_items
    @option_items ||= Pindo::Options::OptionGroup.merge(
        Pindo::Options::BuildOptions.select(:bundleid),
        Pindo::Options::UtilsOptions.select(:test)
    )
end

.optionsObject

命令的选项列表



59
60
61
# File 'lib/pindo/command/appstore/initconfig.rb', line 59

def self.options
    option_items.map(&:to_claide_option).concat(super)
end

Instance Method Details

#runObject



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

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



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

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