rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Rake task with params does not execute #484

Closed tlhampton13 closed 1 year ago

tlhampton13 commented 4 years ago

Checklist

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

  1. create a rake task that take parameters
  2. execute the task from the command line
  3. 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])
timlawrenz commented 3 years ago

@tongueroo do you consider the suggested solution sufficient?

tongueroo commented 3 years ago

Think the suggested approach is fine.

tongueroo commented 1 year ago

@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