-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathcli.cr
107 lines (94 loc) · 2.53 KB
/
cli.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require "option_parser"
require "./commands/*"
module Shards
def self.display_help_and_exit(opts)
puts "shards [options] <command>"
puts
puts "Commands:"
puts " build [targets] [options]"
puts " check"
#puts " info <package>"
puts " init"
puts " install"
puts " list"
puts " prune"
#puts " search <query>"
puts " update"
# puts " update [package package ...]"
puts " version [path]"
puts
puts "Options:"
puts opts
exit
end
def self.run
OptionParser.parse! do |opts|
path = Dir.current
opts.on("--no-color", "") { self.colors = false }
opts.on("--version", "") { puts self.version_string; exit }
opts.on("--production", "") { self.production = true }
opts.on("-v", "--verbose", "") { self.logger.level = Logger::Severity::DEBUG }
opts.on("-q", "--quiet", "") { self.logger.level = Logger::Severity::WARN }
opts.on("-h", "--help", "") { self.display_help_and_exit(opts) }
opts.unknown_args do |args, options|
case args[0]? || DEFAULT_COMMAND
when "build"
build(path, args[1..-1])
when "check"
Commands::Check.run(path)
#when "info"
# display_help_and_exit(opts) unless args[1]?
# Commands::Info.run(args[1])
when "init"
Commands::Init.run(path)
when "install"
Commands::Install.run(path)
when "list"
Commands::List.run(path)
when "prune"
Commands::Prune.run(path)
# when "search"
# display_help_and_exit(opts) unless args[1]?
# Commands::Search.run(path, args[1])
when "update"
Commands::Update.run(path)
# Commands.update(path, *args[1..-1])
when "version"
Commands::Version.run(args[1]? || path)
else
display_help_and_exit(opts)
end
exit
end
end
end
def self.build(path, args)
targets = [] of String
options = [] of String
args.each do |arg|
if arg.starts_with?('-')
options << arg
else
targets << arg
end
end
begin
Commands::Check.run(path)
rescue
Commands::Install.run(path)
end
Commands::Build.run(path, targets, options)
end
end
begin
Shards.run
rescue ex : OptionParser::InvalidOption
Shards.logger.fatal ex.message
exit 1
rescue ex : Shards::ParseError
ex.to_s(STDERR)
exit 1
rescue ex : Shards::Error
Shards.logger.error ex.message
exit 1
end