Class: Pindo::Command::Appstore::Itcapp

Inherits:
Pindo::Command::Appstore show all
Defined in:
lib/pindo/command/appstore/itcapp.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) ⇒ Itcapp

Returns a new instance of Itcapp.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/pindo/command/appstore/itcapp.rb', line 84

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

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

    # 优先使用选项参数,如果没有则使用位置参数,最后默认为当前目录的config.json
    @config_path = @options[:config] || positional_config || File.join(Dir.pwd, 'config.json')
    @app_version = @options[:num]
    @company_name = @options[:com]

    puts "@app_version = #{@app_version}" if @app_version

    super
    @additional_args = argv.remainder!
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项(类方法,避免重复定义)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pindo/command/appstore/itcapp.rb', line 52

def self.option_items
    @option_items ||= [
        Pindo::Options::OptionItem.new(
            key: :config,
            description: '指定config.json文件路径',
            type: String,
            optional: true,
            example: 'pindo appstore itcapp --config=config.json'
        ),
        Pindo::Options::OptionItem.new(
            key: :num,
            description: '指定应用版本号',
            type: String,
            optional: true,
            example: 'pindo appstore itcapp --num=1.0.0'
        ),
        Pindo::Options::OptionItem.new(
            key: :com,
            description: '指定公司名称',
            type: String,
            optional: true,
            example: 'pindo appstore itcapp --com="My Company"'
        )
    ]
end

.optionsObject

命令的选项列表



79
80
81
82
# File 'lib/pindo/command/appstore/itcapp.rb', line 79

def self.options
    # 转换为 CLAide 格式
    option_items.map { |item| item.to_claide_option }.concat(super)
end

Instance Method Details

#runObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pindo/command/appstore/itcapp.rb', line 118

def run
    # 调用 ItcAppHelper 执行 iTunes Connect App 创建流程
    begin
        Pindo::ItcAppHelper.execute_itcapp_creation(
            config_json: @config_json,
            config_path: @config_path,
            app_version: @app_version,
            company_name: @company_name
        )
        puts "\n✓ iTunes Connect App 创建完成!"
    rescue StandardError => e
        puts "\n❌ iTunes Connect App 创建失败: #{e.message}"
        raise e
    end
end

#validate!Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/pindo/command/appstore/itcapp.rb', line 102

def validate!
    super

    # 检查 config.json 文件是否存在
    unless File.exist?(@config_path)
        help! "配置文件不存在: #{@config_path}"
    end

    # 读取并解析 config.json
    begin
        @config_json = JSON.parse(File.read(@config_path))
    rescue JSON::ParserError => e
        help! "配置文件格式错误: #{e.message}"
    end
end