forked from jgraichen/redmine_dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redmine
executable file
·52 lines (43 loc) · 1.25 KB
/
redmine
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
#!/usr/bin/env ruby
REDMINE_VERSION = ENV['REDMINE_VERSION'] = ENV['REDMINE_VERSION'] || ENV['VERSION'] || '3.1.0'
REDMINE_PATH = ENV['REDMINE_PATH'] = File.expand_path("../vendor/redmine/#{REDMINE_VERSION}/", __FILE__)
REDMINE_EXEC = ENV['REDMINE_EXEC'] = File.expand_path(__FILE__)
PLUGIN_PATH = ENV['PLUGIN_PATH'] = File.expand_path("..", __FILE__)
require 'pathname'
SCRIPT_PATH = Pathname.new(__FILE__).expand_path.parent.join('scripts')
def help
<<-HELP.gsub(/^\s{4}/, '')
Available commands:
#{available_commands.join("\n ")}
HELP
end
def available_commands
SCRIPT_PATH.children
.select(&:file?)
.select(&:executable?)
.map(&:basename)
.map(&:to_s)
end
def handle_command(cmd, argv)
unless ARGV[0] =~ /\A(\w+)\z/
STDERR.puts "Invalid command: #{ARGV[0]}"
STDERR.puts help
Kernel.exit 1
end
command = SCRIPT_PATH.join(cmd.to_s)
if command.file? && command.executable?
Kernel.exec command.to_s, *ARGV[1..-1]
else
STDERR.puts "Unknown command: #{ARGV[0]}"
STDERR.puts help
Kernel.exit 1
end
end
case ARGV[0]
when '-h', '--help', nil
STDOUT.puts help
when 'exec'
Dir.chdir(REDMINE_PATH) { Kernel.exec *ARGV[1..-1] }
else
handle_command ARGV[0], ARGV[1..-1]
end