Skip to content
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

Don't add the Workstation path if it is already there in chef shell-init #151

Merged
merged 2 commits into from
Apr 14, 2021

Conversation

nikhil2611
Copy link
Contributor

@nikhil2611 nikhil2611 commented Feb 8, 2021

Signed-off-by: Nikhil Gupta nikhilgupta2102@gmail.com

Description

While initializing the shell via shell-init, this will continue adding workstation locations to the path.
Now corrected the omnibus_env path. This change will check if the path is present in the ENV["PATH"] it will just ignore and if not present then it will add that.

Related Issue

Fixes. https://github.com/chef/chef-cli/issues/93

Signed-off-by: Nikhil Gupta <nikhilgupta2102@gmail.com>
@nikhil2611 nikhil2611 requested review from a team as code owners February 8, 2021 16:02
Copy link
Member

@marcparadise marcparadise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment inline, I think we can do this with less of a change.

Separately, I think that this is a good chance to get some of the testing coverage improved - currently we don't have any tests for ChefCLI::Helpers - which is unfortunate because they underpin parts of chef-clis capabilities.

Could you add a new spec and include tests for omnibus_env? You will likely need to stub out the public methods invoked (omnibus_bin_dir, git_bin_dir, etc) because they mostly rely on omnibus_root- which will explode in omnibus_expand_path if the tests are not run in a place that had an actual omnibus install of chef-cli.

@@ -117,8 +117,15 @@ def omnibus_env
@omnibus_env ||=
begin
user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin"))
path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"] ]
path << git_bin_dir if Dir.exist?(git_bin_dir)
original_path = ENV["PATH"].split(File::PATH_SEPARATOR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would still cause duplicates in the odd case where someone had 1 or 2 of these in their path, but not all three.
But I think we might be able to approach from a different direction - what happens if we assemble our final path as it was, then remove duplicates prior to returning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment inline, I think we can do this with less of a change.

Separately, I think that this is a good chance to get some of the testing coverage improved - currently we don't have any tests for ChefCLI::Helpers - which is unfortunate because they underpin parts of chef-clis capabilities.

Could you add a new spec and include tests for omnibus_env? You will likely need to stub out the public methods invoked (omnibus_bin_dir, git_bin_dir, etc) because they mostly rely on omnibus_root- which will explode in omnibus_expand_path if the tests are not run in a place that had an actual omnibus install of chef-cli.

yeah, i will add a new spec and include tests for omnibus_env.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would still cause duplicates in the odd case where someone had 1 or 2 of these in their path, but not all three.
But I think we might be able to approach from a different direction - what happens if we assemble our final path as it was, then remove duplicates prior to returning?

Got it. Working on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Signed-off-by: Nikhil Gupta <nikhilgupta2102@gmail.com>
@tas50 tas50 changed the title corrected the omnibus_env path Don't add the Workstation path if it is already there in chef shell-init Apr 14, 2021
@tas50 tas50 merged commit 51864a7 into master Apr 14, 2021
@nikhil2611 nikhil2611 deleted the ng/chef-cli_issue_93 branch April 15, 2021 08:33
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

Successfully merging this pull request may close these issues.

None yet

3 participants