Skip to content

rbenv breaks an assumption in bin/dev. #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MrJoy opened this issue Mar 27, 2022 · 8 comments
Closed

rbenv breaks an assumption in bin/dev. #87

MrJoy opened this issue Mar 27, 2022 · 8 comments

Comments

@MrJoy
Copy link
Contributor

MrJoy commented Mar 27, 2022

Because rbenv uses shims, this line in the generated bin/dev script will always return true in an environment in which foreman has been installed in any gemset at any point, even if it's not in the current gemset:

if ! command -v foreman &> /dev/null

I've found this to be a viable alternative that I believe should work everywhere:

if [ $(gem list --local --no-details --quiet --exact foreman | grep foreman | wc -l) -eq 0 ]

(The use of grep is because when foreman isn't installed, gem list will produce an empty line of output.)

@dhh
Copy link
Member

dhh commented Mar 30, 2022

Are there any considerations here re: Windows / WSL we need to account for if we use grep + wc?

@MrJoy
Copy link
Contributor Author

MrJoy commented Mar 30, 2022

That's an excellent question. I've got an engineer who's using WSL that I can ask. I will update the ticket when I have an answer.

Another option might be something like:

if ! type rbenv &> /dev/null
then
  if ! command -v foreman &> /dev/null
  then
    # ...
  fi
else
  if ! foreman version >/dev/null
  then
    # ...
  fi
fi

It's a little more cumbersome to be sure, but it seems like it would be viable. I think it would neatly compartmentalize any potential quirks / changes of semantics to just us rbenv users.

@MrJoy
Copy link
Contributor Author

MrJoy commented Mar 30, 2022

I'm informed by my colleague that when run from a Linux terminal in WSL, grep works fine.

@MrJoy
Copy link
Contributor Author

MrJoy commented Apr 8, 2022

@dhh What can I do to move this forward?

@t27duck
Copy link
Contributor

t27duck commented Apr 13, 2022

Could if ! foreman version &> /dev/null be used across the board regardless if the developer is using rbenv or not?

@MrJoy
Copy link
Contributor Author

MrJoy commented Apr 13, 2022

@t27duck That solution is compatible with rbenv, and certainly seems lower risk. Honestly, I feel silly that it didn't occur to me. Might be worth tossing in a > /dev/null 2>&1 to avoid cluttering output, since you'll get some output to STDOUT/STDERR regardless of which environment you're on. (Edit: Sorry, my shell-fu is weak. Didn't notice the use of &> instead of >.)

@dhh
Copy link
Member

dhh commented Apr 30, 2022

Sounds like @t27duck's solution would do. Feel free to PR that.

@MrJoy
Copy link
Contributor Author

MrJoy commented May 1, 2022

Done.

@dhh dhh closed this as completed May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants