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

Open
#363 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
build-system, cli

Research direction

Run the documented rake -p 'FOO' reproduction and compare it with rake -p 'load_rakefile; FOO'. Then trace the command-line handling for -p, -e, and -E and how load_rakefile is invoked; done means these options load the Rakefile before evaluating user code and the example prints 966.

Written by the indexing model from the issue text.

Description

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?

Dominant language
Ruby
Stars
2.5k
Forks
649
Avg merge
4m
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/rake

All issues in ruby/rake

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.