Rake task with params does not execute
Checklist
- [X ] Upgrade Jets: Are you using the latest version of Jets? This allows Jets to fix issues fast. There's a
jets upgradecommand that makes this a simple task. There's also an Upgrading Guide: http://rubyonjets.com/docs/upgrading/ - [ X] Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.rubyonjets.com
- [X ] Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.
My Environment
| Software | Version |
|---|---|
| Operating System | OSX |
| Jets | 2.3.15 |
| Ruby | 2.5.5 |
Expected Behaviour
When running a custom rake task that has parameters I expect the task to execute.
JETS_ENV=development jets custom:task[0,'foo']
Current Behavior
When running a custom rake task with the following cmd line, the help message is printed instead of executing the task.
JETS_ENV=development jets custom:task[0,'foo']
In the cli.rb file the lookup() method fails to find the task in the namespaced_commands because the parameters don't match.
The value for the custom task in the namespaced_commands is custom:task[arg1,arg2] and the value of the full_command is custom:task[0,'foo'].
The line 138 of cli.rb fails because the parameter portion of the command does not match.
rake_task_found = Jets::Commands::RakeCommand.namespaced_commands.include?(full_command)
Step-by-step reproduction instructions
- create a rake task that take parameters
- execute the task from the command line
- notice the help message is printed instead of executing the task
Code Sample
namespace :custom do
desc "Custom rake task with params."
task :task, [:arg1, :arg2] => :environment do |t, args|
puts "arg1: #{args[:arg1]}"
puts "arg2: #{args[:arg2]}"
end
end
Solution Suggestion
Replace 138 cli.rb
rake_task_found = Jets::Commands::RakeCommand.namespaced_commands.include?(full_command)
with
cmds = Jets::Commands::RakeCommand.namespaced_commands.map {|x| x.split('[')[0]}.compact
rake_task_found = cmds.include?(full_command.split('[')[0])
@tongueroo do you consider the suggested solution sufficient?
Think the suggested approach is fine.
@tlhampton13 Thanks for the detailed report and suggestions to fix it. Details in https://github.com/boltops-tools/jets/pull/651
@timlawrenz No, it quite did not. Fixed an edge case issue with the jets -h. Details in https://github.com/boltops-tools/jets/pull/651