无法使用参数包含空格的调用ruby rake

时间:2018-06-28 20:43:04

标签: ruby syntax parameters arguments rake

我有任务:

desc "Create a team"
task :create_dev_team, [:team_name] do |t, args|
  puts "Creating \"#{args.team_name}\" team under Sub Org ID: 1"
  ESP::Team.create(name: "#{args.team_name}", sub_organization_id: 1)
end

我打电话:

rake create_dev_team[Team Name]

我得到:

rake aborted!
Don't know how to build task 'create_dev_team[Team'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:149:in `invoke_task'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Users/me/.rvm/gems/ruby-2.4.1/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-2.4.1/bin/rake:23:in `load'
/Users/me/.rvm/gems/ruby-2.4.1/bin/rake:23:in `<main>'
/Users/me/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/Users/me/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'

我要怎么做才能使rake接受[Team Name]作为参数?

1 个答案:

答案 0 :(得分:1)

使用segmentRows3.${seg_index}.personRows3.${pers_index},然后用反斜杠运行bash来逃脱空格。