-
Notifications
You must be signed in to change notification settings - Fork 124
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
"itamae list" command to list itamae plugin recipes #321
Open
fuminori-ido
wants to merge
4
commits into
itamae-kitchen:master
Choose a base branch
from
fuminori-ido:list-command-feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
84fe55f
"itamae list" command to list itamae plugin recipes
fuminori-ido f234f5b
ref #321; add spec for 'Itamae::List'
fuminori-ido 80fadc1
use '_' for unused variable
fuminori-ido d5c569e
ref #321; fix failing 'rake spec' under ruby-2.4 env
fuminori-ido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module Itamae | ||
class List | ||
def run | ||
require 'rubygems' | ||
require 'rubygems/exceptions' | ||
require 'pathname' | ||
|
||
pattern = /^itamae-plugin-recipe/ | ||
# from rubygems Gem::Commands::QueryCommand#show_local_gems | ||
specs = Gem::Specification.find_all do |s| | ||
s.name =~ pattern | ||
end | ||
|
||
req = Gem::Requirement.default | ||
dep = Gem::Deprecate.skip_during { Gem::Dependency.new pattern, req } | ||
specs.select! do |s| | ||
dep.match?(s.name, s.version, false) | ||
end | ||
spec_tuples = specs.map do |spec| | ||
[spec.name_tuple, spec] | ||
end | ||
|
||
# from rubygems Gem::Commands::QueryCommand#output_query_results | ||
versions = Hash.new { |h,name| h[name] = [] } | ||
spec_tuples.each do |spec_tuple, source| | ||
versions[spec_tuple.name] << [spec_tuple, source] | ||
end | ||
versions = versions.sort_by do |(n,_),_| | ||
n.downcase | ||
end | ||
|
||
# from rubygems Gem::Commands::QueryCommand#output_versions | ||
versions.each do |gem_name, matching_tuples| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your pointing out! I did so at 80fadc1 |
||
matching_tuples = matching_tuples.sort_by { |n,_| n.version }.reverse | ||
platforms = Hash.new { |h,version| h[version] = [] } | ||
matching_tuples.each do |n, _| | ||
platforms[n.version] << n.platform if n.platform | ||
end | ||
seen = {} | ||
matching_tuples.delete_if do |n,_| | ||
if seen[n.version] | ||
true | ||
else | ||
seen[n.version] = true | ||
false | ||
end | ||
end | ||
scan_lib(matching_tuples[0][1].name, matching_tuples[0][1].gem_dir) | ||
end | ||
end | ||
|
||
private | ||
|
||
def scan_lib(name, dir) | ||
puts name + ' gem:' | ||
Dir.glob(dir + '/lib/itamae/plugin/recipe/**/*.rb') do |f| | ||
puts ' ' + to_recipe_name(f, dir) | ||
end | ||
end | ||
|
||
def to_recipe_name(path, dir) | ||
pn = Pathname.new(path) | ||
relative_path = pn.relative_path_from(Pathname.new(dir + '/lib/itamae/plugin/recipe')).to_s | ||
relative_path.gsub(/\.rb$/, ''). | ||
gsub('/', '::'). | ||
gsub(/::default$/, '') | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@fuminori-ido I can't understand these lines. What purpose of this?