-
Notifications
You must be signed in to change notification settings - Fork 202
/
job2sh
executable file
·46 lines (36 loc) · 950 Bytes
/
job2sh
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
#!/usr/bin/env ruby
LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))
require "#{LKP_SRC}/lib/job2sh.rb"
require "#{LKP_SRC}/lib/job.rb"
require "#{LKP_SRC}/lib/log"
require 'optparse'
require 'ostruct'
require 'yaml'
$opt_file = STDOUT
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{$PROGRAM_NAME} [options] job.yaml"
opts.separator ''
opts.separator 'options:'
opts.on('-o FILE', '--output FILE', 'save shell script to FILE (default: stdout)') do |file|
$opt_file = File.open(file, mode = 'w', perm = 0o775)
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
end
argv = if ARGV == []
['-h']
else
ARGV
end
opt_parser.parse!(argv)
begin
job = Job2sh.new
job.load(ARGV[0])
job.expand_params
rescue Job::ParamError => e
log_error "Abandon job: #{e.message}"
exit 1
end
$opt_file.puts job.to_shell