繁体   English   中英

在快速通道中运行健身脚本时如何获取用户选择的方案?

[英]how to get user selected scheme when running gym script in fastlane?

我已将fastlane添加到我的iOS项目中以创建.ipa

使用以下脚本,我可以创建ipa。

  desc "Generate .ipa"
  lane :createipa do
    gym(clean: true, export_method: ENV["EXPORT_METHOD"], output_directory: ENV["DIRECTORY"])
  end

还有其他2个属性的健身房,一个是计划这是关系到不同的方案,你想创建IPA的一个,另一个是output_name中这是IPA的名称。 现在,当我使用不带方案的脚本时,它要求我在运行时选择方案,我想将运行时的用户输入方案保存到变量中并将其设置为output_name ,有什么办法吗?

由于您在寻找用户输入,为什么在运行fastlane时不只是将方案名称传递给脚本? 像这样:

bundle exec fastlane createipa scheme:MySchemeName

并将您的Fastfile修改为:

  desc "Generate .ipa"
    lane :createipa do |options|
      gym(
        clean: true,
        export_method: ENV["EXPORT_METHOD"],
        output_directory: ENV["DIRECTORY"],
        scheme: options[:scheme]
      )
    end

或者,您可以将其另存为ENV条目:

XCODE_SCHEME=MySchemeName bundle exec fastlane

要直接回答问题,请使用此代码

desc 'Generate the ipa based on the scheme selected by the user'
lane :createipa do
  glob_pattern = 'MyApp/MyApp.xcodeproj/**/*.xcscheme'
  schemes = Dir[glob_pattern].map do |scheme_filepath|
    File.basename(scheme_filepath)
  end
  prompt_text = 'Select a scheme:\n'
  schemes.each_index do |index|
    prompt_text << "  #{index}. #{schemes[index]}\n"
  end
  prompt_text << '> '
  print prompt_text
  selected_scheme_index = gets.to_i
  selected_scheme = schemes[selected_scheme_index]
  puts "Selected Scheme: #{selected_scheme}"

  ipa_output_name "#{selected_scheme}.ipa"

  gym(
    clean: true,
    export_method: ENV['EXPORT_METHOD'],
    output_directory: ENV['DIRECTORY'],
    scheme: selected_scheme,
    output_name: ipa_output_name
  )
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM