-
Notifications
You must be signed in to change notification settings - Fork 4
/
crew.rb
50 lines (45 loc) · 1.09 KB
/
crew.rb
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
require 'fileutils'
require_relative 'library/extend/module.rb'
require_relative 'library/extend/dir.rb'
require_relative 'library/extend/io.rb'
require_relative 'library/exceptions.rb'
require_relative 'library/global.rb'
require_relative 'library/utils.rb'
def split_arguments(arguments)
goptions = []
cmd = 'help'
args = []
# get global options
arguments.each.with_index do |arg, index|
if arg =~ /^-.*/
goptions << arg
break if arg == '--help' or arg == '-h'
else
cmd = arg.to_s.gsub('-', '_').downcase
args = arguments.slice(index + 1, arguments.length)
break
end
end
[goptions, cmd, args]
end
def require_command(cmd)
path = File.join("library", "cmd", cmd + '.rb')
require_relative path
rescue LoadError => e
raise UnknownCommand, cmd, e.backtrace
end
if __FILE__ == $0
begin
goptions, cmd, args = split_arguments(ARGV)
Global.set_options(goptions)
FileUtils.cd(Global::BASE_DIR) do
require_command(cmd)
Crew.send(cmd, args)
end
rescue Exception => e
exception(e)
exit 1
else
exit 0
end
end