-
Notifications
You must be signed in to change notification settings - Fork 313
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
Search for the knife.rb like chef does #383
Conversation
|
||
# Ascending search for .chef directory | ||
Pathname.new(working_dir).ascend do |file| | ||
possibles << file.expand_path if file.basename == '.chef' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be something like:
candidate_directory = File.join(file.expand_path, '.chef')
if File.exist?(candidate_directory) && File.directory?(candidate_directory)
possibles << File.join(candidate_directory, 'knife.rb')
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure it's fundamentally the same, no?
Search upward and add anything that is .chef
. I could add the directory?
check, but the actual existence check is done later at line ~45.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the directory check in 0b8005a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory check wasn't my concern, I'm confused on how this code:
Pathname.new(working_dir).ascend do |file|
possibles << file.expand_path if file.basename == '.chef' && file.directory?
end
will ever actually get a .chef
directory. For example:
% irb
irb(main):001:0> require 'pathname'
=> true
irb(main):002:0> p = Pathname.new(Dir.pwd)
=> #<Pathname:/Users/schisamo/dev/code/opscode-cookbooks/opscode-ci>
irb(main):003:0> p.ascend{ |file| puts "Path = #{file}, Basename = #{file.basename}" }
Path = /Users/schisamo/dev/code/opscode-cookbooks/opscode-ci, Basename = opscode-ci
Path = /Users/schisamo/dev/code/opscode-cookbooks, Basename = opscode-cookbooks
Path = /Users/schisamo/dev/code, Basename = code
Path = /Users/schisamo/dev, Basename = dev
Path = /Users/schisamo, Basename = schisamo
Path = /Users, Basename = Users
Path = /, Basename = /
=> nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I just realized this in refactoring my tests. Push coming soon 😄
@schisamo re-review please when you have a chance? |
Are we merging this, or moving to a new gem? |
I'm indifferent. @reset? |
We should merge it in and then refactor it if at anytime a gem exists which replicates the functionality |
Search for the knife.rb like chef does
See: #382