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
34
34
test : test_unit test_integration
35
35
36
36
test_unit : phony
37
- $(CRYSTAL ) run test/* _test.cr
37
+ $(CRYSTAL ) run test/* _test.cr test/commands/ * _test.cr
38
38
39
39
test_integration : bin/shards phony
40
40
$(CRYSTAL ) run test/integration/* _test.cr
Original file line number Diff line number Diff line change @@ -39,6 +39,28 @@ dependencies are satisfied,
39
39
dependencies aren't satisfied.
40
40
.RE
41
41
.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
42
64
\fB init \fR
43
65
.RS 4
44
66
Initializes 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
9
9
Commands:
10
10
build [<targets>] [<options>] - Build the specified <targets> in `bin` path.
11
11
check - Verify all dependencies are installed.
12
+ info [--name | --version] - Show information about a shard.
12
13
init - Initialize a `shard.yml` file.
13
14
install - Install dependencies, creating or using the `shard.lock` file.
14
15
list [--tree] - List installed dependencies.
@@ -41,6 +42,8 @@ module Shards
41
42
build(path, args)
42
43
when " check"
43
44
Commands ::Check .run(path)
45
+ when " info"
46
+ Commands ::Info .run(path, args)
44
47
when " init"
45
48
Commands ::Init .run(path)
46
49
when " install"
@@ -64,7 +67,7 @@ module Shards
64
67
args.reject(& .starts_with?(" --" ))
65
68
)
66
69
when " version"
67
- Commands ::Version .run(args[ 1 ] ? || path)
70
+ Commands ::Info .run(args.shift ? || path, [ " --version " ] )
68
71
when " --version"
69
72
puts self .version_string
70
73
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
+
1
3
module Shards
2
4
module CliHelper
3
5
def before_setup
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class FailedCommand < Exception
3
3
getter stderr : String
4
4
5
5
def initialize (message, @stdout , @stderr )
6
- super message
6
+ super " #{ message } : #{ stderr } "
7
7
end
8
8
end
9
9
You can’t perform that action at this time.
0 commit comments