-
Notifications
You must be signed in to change notification settings - Fork 0
/
u
executable file
·73 lines (57 loc) · 1.83 KB
/
u
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
#!/usr/bin/env ruby
if ARGV.length == 0
abort 'Please provide a command'
end
$start_time = Time.now
def require_dir(dir)
Dir[File.join(__dir__, dir, '*.rb')].each { |file| require_relative file[0..-4] }
end
def require_uscripts
Dir[File.join(Dir.pwd, '*.uscript.rb')].each { |file| require_relative file[0..-4] }
end
require 'pry'
require 'terminal-notifier'
THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
$LOAD_PATH.unshift "#{File.dirname(THIS_FILE)}/lib"
$LOAD_PATH.unshift "#{File.dirname(THIS_FILE)}/ext"
require 'u'
require 'package'
U::Package.bootstrap U::CONFIG_DIR
require_dir 'ext' # The extension libraries that may be needed by packages
require_dir 'packages' # The actual scripts that will be registered
require_uscripts
command = ARGV.join(' ').split(':', 2)
script_name = command.shift
arguments = command.join.strip.split(' ')
if script = U::Package.scripts[script_name]
parameters = U::Package.get_script_params script
if arguments.length != parameters.length
case parameters.length
when 0
U::Package.uprint "The command \"#{script_name}\" takes no parameters"
exit 0
when 1
U::Package.uprint "The command \"#{script_name}\" requires a #{parameters.join}"
exit 0
when 2
U::Package.uprint "The command \"#{script_name}\" requires #{parameters.join(' and ')}"
exit 0
else
last_arg = parameters.pop
U::Package.uprint "The command \"#{script_name}\" requires #{parameters.join(', ')}, and #{last_arg}"
exit 0
end
end
begin
if arguments.empty?
script.call
else
script.call *arguments
end
rescue U::Core::FeatureDisabled => e
U::Package.uprint "Error calling '#{script_name}'", :error
U::Package.uprint e, :error
end
else
U::Package.uprint "No script matching \"#{ARGV.join(' ')}\""
end