-
Notifications
You must be signed in to change notification settings - Fork 107
/
redmine
executable file
·55 lines (45 loc) · 1.3 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
53
54
55
#!/usr/bin/env ruby
# frozen_string_literal: true
DEFAULT_VERSION = '6.0.1'
REDMINE_VERSION = ENV['REDMINE_VERSION'] = ENV.fetch('REDMINE_VERSION') { ENV.fetch('VERSION') { DEFAULT_VERSION } }
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(__dir__)
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 /\A(\w+)\z/.match?(ARGV[0])
warn "Invalid command: #{ARGV[0]}"
warn help
Kernel.exit 1
end
command = SCRIPT_PATH.join(cmd.to_s)
if command.file? && command.executable?
Kernel.exec command.to_s, *ARGV[1..]
else
warn "Unknown command: #{ARGV[0]}"
warn 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..]) }
else
handle_command ARGV[0], ARGV[1..]
end