rake icon indicating copy to clipboard operation
rake copied to clipboard

load Rakefile before executing `-p`, `-e`, and `-E` code

Open avdi opened this issue 5 years ago • 0 comments

Let's say we have this sad little Rakefile:

FOO=23*42

And we want to find out the value of FOO. We look at the --help output, and -p sounds promising:

$ rake --help
    ...
    -p, --execute-print CODE         Execute some Ruby code, print the result, then exit.
    ...

But when we try it...

$ rake -p 'FOO'
rake aborted!
NameError: uninitialized constant Rake::Application::FOO

(See full trace by running task with --trace)

...this is confusing! Especially for a Rake novice.

We can get the result we intended:

$ rake -p 'load_rakefile; FOO'
966

But this requires substantial inner knowledge of Rake.

Suggested behavior:

$ rake -p 'FOO'
966

Thoughts, anyone? Is there a reason I'm missing that -e, -E, and -p don't load the rakefile by default?

avdi avatar Sep 29 '20 15:09 avdi