-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f60825
commit eba93e4
Showing
9 changed files
with
144 additions
and
35 deletions.
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
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,56 @@ | ||
require "./command" | ||
|
||
module Shards | ||
module Commands | ||
class Info < Command | ||
def initialize(path) | ||
super lookup_path(path) | ||
end | ||
|
||
def display_help | ||
puts <<-HELP | ||
shards info [<command>] | ||
Displays information about a shard. | ||
Commands: | ||
--name - Print the name of the shard. | ||
--version - Print the version in `spec.yml`. | ||
-h, --help - Print usage synopsis. | ||
If no command is given, a summary including name and version is printed. | ||
HELP | ||
end | ||
|
||
def run(args, *, stdout = STDOUT) | ||
case args.shift? | ||
when "--name" | ||
stdout.puts spec.name | ||
when "--version" | ||
stdout.puts spec.version | ||
when "--help", "-h" | ||
display_help | ||
else | ||
stdout.puts " name: #{spec.name}" | ||
stdout.puts "version: #{spec.version}" | ||
end | ||
end | ||
|
||
# look up for `SPEC_FILENAME` in *path* or up | ||
private def lookup_path(path) | ||
previous = nil | ||
current = File.expand_path(path) | ||
|
||
until !File.directory?(current) || current == previous | ||
shard_file = File.join(current, SPEC_FILENAME) | ||
break if File.exists?(shard_file) | ||
|
||
previous = current | ||
current = File.dirname(current) | ||
end | ||
|
||
current | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
require "../../src/commands/info" | ||
require "../test_helper" | ||
require "../support/cli" | ||
|
||
private def capture(command, *args) | ||
String.build do |io| | ||
command.run(args.to_a, stdout: io) | ||
end.chomp | ||
end | ||
|
||
class Shards::Commands::InfoTest < Minitest::Test | ||
def test_reports_name | ||
with_shard({name: "foo", version: "1.2.3"}) do | ||
info = Shards::Commands::Info.new(application_path) | ||
|
||
assert_equal "foo", capture(info, "--name") | ||
assert_equal "1.2.3", capture(info, "--version") | ||
assert_equal <<-OUT, capture(info, "") | ||
name: foo | ||
version: 1.2.3 | ||
OUT | ||
end | ||
end | ||
end |
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,34 @@ | ||
require "../integration_helper" | ||
|
||
class InfoCommandTest < Minitest::Test | ||
def test_reports_name | ||
Dir.cd(application_path) do | ||
with_shard({name: "foo"}) do | ||
output = run "shards info --name", capture: true | ||
assert_match "foo", output | ||
end | ||
end | ||
end | ||
|
||
def test_reports_version | ||
Dir.cd(application_path) do | ||
with_shard({version: "1.2.3"}) do | ||
output = run "shards info --version", capture: true | ||
assert_match "1.2.3", output | ||
end | ||
end | ||
end | ||
|
||
def test_reports_info | ||
Dir.cd(application_path) do | ||
with_shard({name: "foo", version: "1.2.3"}) do | ||
output = run "shards info", capture: true | ||
assert_match <<-OUT, output | ||
name: foo | ||
version: 1.2.3 | ||
OUT | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require "./factories" | ||
|
||
module Shards | ||
module CliHelper | ||
def before_setup | ||
|
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