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

About-command #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ PATH
specs:
bundler-toolbox (0.1.0)
dry-cli (~> 0.6.0)
liquid
rainbow (>= 3.0.0)
rubytoolbox-api (>= 0.2.0)

GEM
Expand Down Expand Up @@ -69,6 +71,7 @@ GEM
guard-rubocop (1.3.0)
guard (~> 2.0)
rubocop (~> 0.20)
liquid (4.0.3)
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down
3 changes: 3 additions & 0 deletions bundler-toolbox.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Gem::Specification.new do |spec|
spec.add_dependency "dry-cli", "~> 0.6.0"
spec.add_dependency "rubytoolbox-api", ">= 0.2.0"

spec.add_dependency "liquid"
spec.add_dependency "rainbow", ">= 3.0.0"

spec.add_development_dependency "rubocop"
spec.add_development_dependency "rubocop-performance"
spec.add_development_dependency "rubocop-rspec"
Expand Down
53 changes: 53 additions & 0 deletions lib/bundler/toolbox/cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "dry/cli"
require "liquid"
require "rainbow"

module Bundler
module Toolbox
Expand Down Expand Up @@ -52,7 +54,58 @@ def call(info: false, **)
end
end

class About < Dry::CLI::Command
module RainbowFilter
def color(input, color)
Rainbow(input).color(color.to_sym)
end

def bg(input, color)
Rainbow(input).background(color.to_sym)
end

def bold(input)
Rainbow(input).bright
end

def underline(input)
Rainbow(input).underline
end
end

desc "Get information about given gem(s)"

argument :gems, type: :array,
required: true,
desc: "Name(s) of gems to print information about"

option :fixtures, type: :boolean,
default: false,
desc: "For testing purposues: Do not make actual API calls, use local fixtures"

def call(gems:, fixtures:, **)
Bundler::Toolbox.compare(*gems, fixtures: fixtures).each do |project|
puts format_project(project)
end
end

private

def template_path(filename)
File.join(__dir__, "..", "..", "..", "templates", filename)
end

def template
@template ||= Liquid::Template.parse File.read(template_path("about.liquid"))
end

def format_project(project)
template.render project.to_h, filters: [RainbowFilter]
end
end

register "version", Version, aliases: ["v", "-v", "--version"]
register "about", About, aliases: ["a"]
end
end
end
12 changes: 12 additions & 0 deletions spec/bundler/toolbox/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,16 @@ def invoke(*args)
.to output(/Execution environment: #{described_class.execution_environment}/).to_stdout
end
end

describe "About Command" do
it "prints information about requested gem" do
expect { invoke "about", "simplecov", "--fixtures" }
.to output(/Code coverage for Ruby with a powerful configuration library/)
.to_stdout
end

it "debug" do
invoke "about", "simplecov", "--fixtures"
end
end
end
30 changes: 30 additions & 0 deletions templates/about.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ name | color: "red" | bold }} | Score {{ score }}

{% if description %}{{ description | color: "darkgray" }}{% endif %}

{% if categories %}
{{ "Categories" | bold }}
==========
{% for category in categories %}
{{ category.name | bold }} {{ category.urls.toolbox_url | color: "darkgray" | underline }}

{{ category.description | color: "darkgray" }}
{% endfor %}
{% endif %}

{% if rubygem %}
## Rubygem [{{ rubygem.name }}]({{ rubygem.url}})

* **Downloads** {{ rubygem.stats.downloads }}
* **Reverse Dependencies** {{ rubygem.stats.reverse_dependencies_count }}
* **Total Releases** {{ rubygem.stats.releases_count }}
{% endif %}


{% if github_repo %}
## Github Repo [{{ github_repo.path }}]({{ github_repo.url}})

* **Stargazers** {{ github_repo.stats.stargazers_count }}
* **Forks** {{ github_repo.stats.forks_count }}
* **Watchers** {{ github_repo.stats.watchers_count }}
{% endif %}