Having a simple rake task:
task :ws, [:str] => :environment do |t, args|
puts args.str.inspect
end
I get following results when run this task in command line:
$ rake ws[' ']
nil
$ rake ws[' ']
nil
$ rake ws[' 1']
" 1"
$ rake ws[' 1 ']
" 1"
$ rake 'ws[ ]'
nil
$ rake 'ws[ ]'
nil
$ rake 'ws[ 1]'
" 1"
$ rake 'ws[ 1 ]'
" 1"
While when the task is being invoked in rails console everything works as expected:
2.3.3 :258 > Rake::Task['ws'].invoke(' ')
" "
2.3.3 :259 > Rake::Task['ws'].reenable
2.3.3 :260 > Rake::Task['ws'].invoke(' ')
" "
2.3.3 :261 > Rake::Task['ws'].reenable
2.3.3 :262 > Rake::Task['ws'].invoke(' 1')
" 1"
2.3.3 :263 > Rake::Task['ws'].reenable
2.3.3 :264 > Rake::Task['ws'].invoke(' 1 ')
" 1 "
Again, it is definitely not the OS who is responsible for that trimming, since it shouldn't trim anything between quote marks. And besides it can be easily tested this way:
task :ws, [:str] => :environment do |t, args|
puts args.str.inspect
puts ARGV[1].inspect
end
then in command line:
$ rake 'ws[ 1 ]' ' 2 '
" 1"
" 2 "
Can trailing whitespaces be somehow preserved when task is being run in command line ? Without using command line parameters (' 2 '
in the example above) since Rake will try to execute a task for each such parameter and will raise an error if a task is not found, or even worse if it finds a task then it will execute it.
Rake version 12.0.0