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

Added time sort option for list command #617

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rubygems/commands/list_command.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Gem::Commands::ListCommand < Gem::Commands::QueryCommand


def initialize def initialize
super 'list', 'Display gems whose name starts with STRING' super 'list', 'Display gems whose name starts with STRING'

add_option('-t', '--time', 'Sort gem(s) according to latest version release') do |value, options|
options[:time] = value
end


remove_option('--name-matches') remove_option('--name-matches')
end end
Expand Down
16 changes: 13 additions & 3 deletions lib/rubygems/commands/query_command.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -162,9 +162,12 @@ def output_query_results(spec_tuples)
spec_tuples.each do |spec_tuple, source| spec_tuples.each do |spec_tuple, source|
versions[spec_tuple.name] << [spec_tuple, source] versions[spec_tuple.name] << [spec_tuple, source]
end end

versions = versions.sort_by do |(n,_), tuples|
versions = versions.sort_by do |(n,_),_| if options[:time]
n.downcase [tuples.first[1].date, n.downcase]
else
n.downcase
end
end end


output_versions output, versions output_versions output, versions
Expand Down Expand Up @@ -210,6 +213,7 @@ def entry_details entry, detail_tuple, specs, platforms
spec_authors entry, spec spec_authors entry, spec
spec_homepage entry, spec spec_homepage entry, spec
spec_license entry, spec spec_license entry, spec
spec_date entry, spec
spec_loaded_from entry, spec, specs spec_loaded_from entry, spec, specs
spec_summary entry, spec spec_summary entry, spec
end end
Expand Down Expand Up @@ -261,6 +265,12 @@ def spec_homepage entry, spec


entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4) entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
end end

def spec_date entry, spec
return if spec.date.nil?

entry << "\n" << format_text("Date: #{spec.date.strftime('%b %d, %Y')}", 68, 4)
end


def spec_license entry, spec def spec_license entry, spec
return if spec.license.nil? or spec.license.empty? return if spec.license.nil? or spec.license.empty?
Expand Down