@@ -2,7 +2,7 @@ require "option_parser"
2
2
require " ./commands/*"
3
3
4
4
module Shards
5
- def self.display_help_and_exit (opts )
5
+ def self.display_help (opts )
6
6
puts <<-HELP
7
7
shards [<options>...] [<command>]
8
8
@@ -17,29 +17,29 @@ module Shards
17
17
prune - Remove unused dependencies from `lib` folder.
18
18
update [<shards>] - Update dependencies and `shard.lock`.
19
19
version [<path>] - Print the current version of the shard.
20
+ --version - Print the `shards` version.
21
+ -h, --help - Print usage synopsis.
20
22
21
23
Options:
22
24
HELP
23
25
puts opts
24
- exit
25
26
end
26
27
27
28
def self.run
28
29
OptionParser .parse(ARGV ) do |opts |
29
30
path = Dir .current
30
31
31
32
opts.on(" --no-color" , " Disable colored output." ) { self .colors = false }
32
- opts.on(" --version" , " Print the `shards` version." ) { puts self .version_string; exit }
33
33
opts.on(" --production" , " Run in release mode. No development dependencies and strict sync between shard.yml and shard.lock." ) { self .production = true }
34
34
opts.on(" --local" , " Don't update remote repositories, use the local cache only." ) { self .local = true }
35
+ opts.on(" -h" , " --help" , " Print usage synopsis." ) { self .display_help_and_exit(opts) }
35
36
opts.on(" -v" , " --verbose" , " Increase the log verbosity, printing all debug statements." ) { self .set_debug_log_level }
36
37
opts.on(" -q" , " --quiet" , " Decrease the log verbosity, printing only warnings and errors." ) { self .set_warning_log_level }
37
- opts.on(" -h" , " --help" , " Print usage synopsis." ) { self .display_help_and_exit(opts) }
38
38
39
39
opts.unknown_args do |args , options |
40
- case args[ 0 ] ? || DEFAULT_COMMAND
40
+ case args.shift ? || DEFAULT_COMMAND
41
41
when " build"
42
- build(path, args[ 1 .. - 1 ] )
42
+ build(path, args)
43
43
when " check"
44
44
Commands ::Check .run(path)
45
45
when " init"
@@ -51,7 +51,7 @@ module Shards
51
51
when " lock"
52
52
Commands ::Lock .run(
53
53
path,
54
- args[ 1 .. - 1 ] .reject(& .starts_with?(" --" )),
54
+ args.reject(& .starts_with?(" --" )),
55
55
print: args.includes?(" --print" ),
56
56
update: args.includes?(" --update" )
57
57
)
@@ -62,12 +62,17 @@ module Shards
62
62
when " update"
63
63
Commands ::Update .run(
64
64
path,
65
- args[ 1 .. - 1 ] .reject(& .starts_with?(" --" ))
65
+ args.reject(& .starts_with?(" --" ))
66
66
)
67
67
when " version"
68
68
Commands ::Version .run(args[1 ]? || path)
69
+ when " --version"
70
+ puts self .version_string
71
+ when " -h" , " --help"
72
+ display_help(opts)
69
73
else
70
- display_help_and_exit(opts)
74
+ display_help(opts)
75
+ exit 1
71
76
end
72
77
73
78
exit
0 commit comments