语法错误,意外 =>,期待结束
Posted
技术标签:
【中文标题】语法错误,意外 =>,期待结束【英文标题】:syntax error, unexpected =>, expecting end 【发布时间】:2021-09-14 07:45:03 【问题描述】:我正在尝试添加一个 if 语句来“交付”fastlane 的操作。
我将 fastlane 与 bitrise 一起使用,我遇到的问题是,当我将 if 语句添加到工作语句时,它总是抛出以下语法错误:“”
这是我拥有的 Fastfile 的代码:
default_platform(:ios)
platform :ios do
desc "TEST"
lane :testEnv do
deliver(
app_version: ENV['APP_VERSION'],
app_rating_config_path: "./fastlane/app_store_rating_config.json",
submit_for_review: false,
screenshots_path: "./fastlane/screenshots/",
metadata_path: "./fastlane/metadata/",
force: true,
#overwrite_screenshots: true,
price_tier: 0,
build_number: ENV['BITRISE_BUILD_NUMBER'],
precheck_include_in_app_purchases: false,
copyright: "#Time.now.year",
primary_category: "EDUCATION",
secondary_category: "BOOKS",
automatic_release: false,
release_notes:
if ENV['RELEASE_NOTES_ES'] != nil
"es-ES" => ENV['RELEASE_NOTES_ES'],
end
if ENV['RELEASE_NOTES_EN'] != nil
"en-GB" => ENV['RELEASE_NOTES_EN'],
end
if ENV['RELEASE_NOTES_PT'] != nil
"pt-BR" => ENV['RELEASE_NOTES_PT'],
end
if ENV['RELEASE_NOTES_ZH'] != nil
"zh-Hans" => ENV['RELEASE_NOTES_ZH'],
end
if ENV['RELEASE_NOTES_CA'] != nil
"ca" => ENV['RELEASE_NOTES_CA'],
end
,
privacy_url:
if ENV['PRIVACY_URL_ES'] != nil
"es-ES" => ENV['PRIVACY_URL_ES']
end
if ENV['PRIVACY_URL_EN'] != nil
"en-GB" => ENV['PRIVACY_URL_EN']
end
if ENV['PRIVACY_URL_PT'] != nil
"pt-BR" => ENV['PRIVACY_URL_PT']
end
if ENV['PRIVACY_URL_EN'] != nil
"zh-Hans" => ENV['PRIVACY_URL_EN']
end
if ENV['PRIVACY_URL_ES'] != nil
"ca" => ENV['PRIVACY_URL_ES']
end
,
support_url:
if ENV['SUPPORT_URL_ES'] != nil
"es-ES" => ENV['SUPPORT_URL_ES'],
end
if ENV['SUPPORT_URL_EN'] != nil
"en-GB" => ENV['SUPPORT_URL_EN'],
end
if ENV['SUPPORT_URL_PT'] != nil
"pt-BR" => ENV['SUPPORT_URL_PT'],
end
if ENV['SUPPORT_URL_EN'] != nil
"zh-Hans" => ENV['SUPPORT_URL_EN'],
end
if ENV['SUPPORT_URL_ES'] != nil
"ca" => ENV['SUPPORT_URL_ES'],
end
,
#APP METADATA INFORMATION
name:
if ENV['DESCRIPTION_ES'] != nil
"es-ES" => ENV['APP_NAME'],
end
if ENV['DESCRIPTION_EN'] != nil
"en-GB" => ENV['APP_NAME'],
end
if ENV['DESCRIPTION_PT'] != nil
"pt-BR" => ENV['APP_NAME'],
end
if ENV['DESCRIPTION_ZH'] != nil
"zh-Hans" => ENV['APP_NAME'],
end
if ENV['DESCRIPTION_CA'] != nil
"ca" => ENV['APP_NAME'],
end
,
description:
if ENV['DESCRIPTION_ES'] != nil
"es-ES" => ENV['DESCRIPTION_ES'],
end
if ENV['DESCRIPTION_EN'] != nil
"en-GB" => ENV['DESCRIPTION_EN'],
end
if ENV['DESCRIPTION_PT'] != nil
"pt-BR" => ENV['DESCRIPTION_PT'],
end
if ENV['DESCRIPTION_ZH'] != nil
"zh-Hans" => ENV['DESCRIPTION_ZH'],
end
if ENV['DESCRIPTION_CA'] != nil
"ca" => ENV['DESCRIPTION_CA'],
end
,
keywords:
if ENV['KEYWORDS_EN'] != nil
"en-GB" => ENV['KEYWORDS_EN'],
end
if ENV['KEYWORDS_ES'] != nil
"es-ES" => ENV['KEYWORDS_ES'],
end
if ENV['KEYWORDS_PT'] != nil
"pt-BR" => ENV['KEYWORDS_PT'],
end
if ENV['KEYWORDS_ZH'] != nil
"zh-Hans" => ENV['KEYWORDS_ZH'],
end
if ENV['KEYWORDS_CA'] != nil
"ca" => ENV['KEYWORDS_ES'],
end
,
submission_information:
add_id_info_uses_idfa: false,
content_rights_contains_third_party_content: false,
export_compliance_platform: 'ios',
export_compliance_compliance_required: false,
export_compliance_encryption_updated: false,
export_compliance_uses_encryption: false,
content_rights_has_rights: false
,
app_review_information:
first_name: "Name",
last_name: "Surname",
phone_number: "+34 99999999",
email_address: "name@mail.com",
demo_user: ENV['DEMO_USER'],
demo_password: ENV['DEMO_PASS'],
)
end
end
这是我完整的 Fastfile,问题是在我的项目中,我们有很多针对不同客户的目标,每个目标都使用不同的语言。我所做的是将这些信息保存在 bitrise 机器上的环境变量(它们在 bitrise yml 上定义)。
如您所见,我正在尝试根据环境变量添加不同的语言,如果存在也编写这种语言,但它不起作用。我不完全知道问题出在哪里,因为当我没有 ifs 时,它就像这个例子一样工作:
description:
"es-ES" => ENV['DESCRIPTION_ES'],
"en-GB" => ENV['DESCRIPTION_EN'],
"pt-BR" => ENV['DESCRIPTION_PT'],
"zh-Hans" => ENV['DESCRIPTION_ZH'],
"ca" => ENV['DESCRIPTION_CA'],
,
这段代码可以正常工作。
我对 ruby 语法了解不多,所以也许在你的帮助下我可以做到这一点,这会节省我很多时间。
谢谢!
【问题讨论】:
请确保构造一个minimal reproducible example。请注意,所有这三个词都很重要:它应该只是一个示例,您不应该发布整个实际代码,而应该创建一个简化的示例来演示您的问题。此外,它应该是minimal,即它不应该包含证明问题所必需的任何内容。 (大多数初学者问题可以用不到 5 行简单的代码来演示。)而且它应该是reproducible,这意味着如果我复制并粘贴并运行代码,我应该会看到与您完全相同的问题见。 idownvotedbecau.se/toomuchcodeidownvotedbecau.se/nomcve 嗨@JörgWMittag,也许这几行就足够了:如果ENV['DESCRIPTION_ES'] != nil "es-ES" => ENV['DESCRIPTION_ES'],结束我使用这个网页@ 987654324@查看错误 【参考方案1】:很遗憾,这是无效的 ruby 语法:
if ENV['RELEASE_NOTES_ES'] != nil
"es-ES" => ENV['RELEASE_NOTES_ES'],
end
有several ways you could add conditional elements to a hash in ruby,如:
.tap do |my_hash|
my_hash[:a] = 'a'
my_hash[:b] = 'b' if condition
end
或者:
:a => 'a'.merge( condition ? :b => 'b' : )
或者:
hash = a: 'a', b: 'b'
hash[:c] = 'c' if condition
...但是对于您的用例,由于您要做的只是删除具有nil
值的哈希元素,因此我将使用Hash#compact
:
release_notes:
"es-ES" => ENV['RELEASE_NOTES_ES'],
"en-GB" => ENV['RELEASE_NOTES_EN'],
"pt-BR" => ENV['RELEASE_NOTES_PT'],
"zh-Hans" => ENV['RELEASE_NOTES_ZH'],
"ca" => ENV['RELEASE_NOTES_CA']
.compact
【讨论】:
是的,这正是我所需要的,非常感谢!!以上是关于语法错误,意外 =>,期待结束的主要内容,如果未能解决你的问题,请参考以下文章
Laravel:获取刀片组件语法错误,意外的“endif”(T_ENDIF),期待文件结束
Rails 升级的语法错误,意外的 '\n',期待 => (SyntaxError)