File tree Expand file tree Collapse file tree 9 files changed +144
-35
lines changed Expand file tree Collapse file tree 9 files changed +144
-35
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ uninstall: phony
3434test : test_unit test_integration
3535
3636test_unit : phony
37- $(CRYSTAL ) run test/* _test.cr
37+ $(CRYSTAL ) run test/* _test.cr test/commands/ * _test.cr
3838
3939test_integration : bin/shards phony
4040 $(CRYSTAL ) run test/integration/* _test.cr
Original file line number Diff line number Diff line change @@ -39,6 +39,28 @@ dependencies are satisfied,
3939dependencies aren't satisfied.
4040.RE
4141.PP
42+ \fB info [<command>] \fR
43+ .RS 4
44+ Displays information about a shard.
45+ .SS
46+ .RS 4
47+ Commands:
48+ .PP
49+ .TP 3
50+ \fB --name \fR
51+ Print the name of the shard.
52+ .TP 3
53+ \fB --version \fR
54+ Print the version in `spec.yml`.
55+ .TP 3
56+ \fB -h, --help \fR
57+ Print usage synopsis.
58+ .RE
59+ .PP
60+ .RS 4
61+ If no command is given, a summary including name and version is printed.
62+ .RE
63+ .PP
4264\fB init \fR
4365.RS 4
4466Initializes a default \fI shard.yml \fR in the current folder.
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ module Shards
99 Commands:
1010 build [<targets>] [<options>] - Build the specified <targets> in `bin` path.
1111 check - Verify all dependencies are installed.
12+ info [<options>...] - Show information about a shard. Pass `--help` for details.
1213 init - Initialize a `shard.yml` file.
1314 install - Install dependencies, creating or using the `shard.lock` file.
1415 list [--tree] - List installed dependencies.
@@ -41,6 +42,8 @@ module Shards
4142 build(path, args)
4243 when " check"
4344 Commands ::Check .run(path)
45+ when " info"
46+ Commands ::Info .run(path, args)
4447 when " init"
4548 Commands ::Init .run(path)
4649 when " install"
@@ -64,7 +67,7 @@ module Shards
6467 args.reject(& .starts_with?(" --" ))
6568 )
6669 when " version"
67- Commands ::Version .run(args[ 1 ] ? || path)
70+ Commands ::Info .run(args.shift ? || path, [ " --version " ] )
6871 when " --version"
6972 puts self .version_string
7073 when " -h" , " --help"
Original file line number Diff line number Diff line change 1+ require " ./command"
2+
3+ module Shards
4+ module Commands
5+ class Info < Command
6+ def initialize (path )
7+ super lookup_path(path)
8+ end
9+
10+ def display_help
11+ puts <<-HELP
12+ shards info [<command>]
13+
14+ Displays information about a shard.
15+
16+ Commands:
17+ --name - Print the name of the shard.
18+ --version - Print the version in `spec.yml`.
19+ -h, --help - Print usage synopsis.
20+
21+ If no command is given, a summary including name and version is printed.
22+ HELP
23+ end
24+
25+ def run (args, * , stdout = STDOUT )
26+ case args.shift?
27+ when " --name"
28+ stdout.puts spec.name
29+ when " --version"
30+ stdout.puts spec.version
31+ when " --help" , " -h"
32+ display_help
33+ else
34+ stdout.puts " name: #{ spec.name } "
35+ stdout.puts " version: #{ spec.version } "
36+ end
37+ end
38+
39+ # look up for `SPEC_FILENAME` in *path* or up
40+ private def lookup_path (path )
41+ previous = nil
42+ current = File .expand_path(path)
43+
44+ until ! File .directory?(current) || current == previous
45+ shard_file = File .join(current, SPEC_FILENAME )
46+ break if File .exists?(shard_file)
47+
48+ previous = current
49+ current = File .dirname(current)
50+ end
51+
52+ current
53+ end
54+ end
55+ end
56+ end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ require " ../../src/commands/info"
2+ require " ../test_helper"
3+ require " ../support/cli"
4+
5+ private def capture (command , * args )
6+ String .build do |io |
7+ command.run(args.to_a, stdout: io)
8+ end .chomp
9+ end
10+
11+ class Shards::Commands::InfoTest < Minitest::Test
12+ def test_reports_name
13+ with_shard({name: " foo" , version: " 1.2.3" }) do
14+ info = Shards ::Commands ::Info .new(application_path)
15+
16+ assert_equal " foo" , capture(info, " --name" )
17+ assert_equal " 1.2.3" , capture(info, " --version" )
18+ assert_equal <<-OUT , capture(info, "")
19+ name: foo
20+ version: 1.2.3
21+ OUT
22+ end
23+ end
24+ end
Original file line number Diff line number Diff line change 1+ require " ../integration_helper"
2+
3+ class InfoCommandTest < Minitest::Test
4+ def test_reports_name
5+ Dir .cd(application_path) do
6+ with_shard({name: " foo" }) do
7+ output = run " shards info --name" , capture: true
8+ assert_match " foo" , output
9+ end
10+ end
11+ end
12+
13+ def test_reports_version
14+ Dir .cd(application_path) do
15+ with_shard({version: " 1.2.3" }) do
16+ output = run " shards info --version" , capture: true
17+ assert_match " 1.2.3" , output
18+ end
19+ end
20+ end
21+
22+ def test_reports_info
23+ Dir .cd(application_path) do
24+ with_shard({name: " foo" , version: " 1.2.3" }) do
25+ output = run " shards info" , capture: true
26+ assert_match <<-OUT , output
27+ name: foo
28+ version: 1.2.3
29+
30+ OUT
31+ end
32+ end
33+ end
34+ end
Original file line number Diff line number Diff line change 1+ require " ./factories"
2+
13module Shards
24 module CliHelper
35 def before_setup
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class FailedCommand < Exception
33 getter stderr : String
44
55 def initialize (message, @stdout , @stderr )
6- super message
6+ super " #{ message } : #{ stderr } "
77 end
88end
99
You can’t perform that action at this time.
0 commit comments