-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvivosnap.rb
executable file
·51 lines (44 loc) · 1.19 KB
/
vivosnap.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
51
#! /usr/bin/env ruby
require_relative 'common'
class Vivosnap
COMMANDS = [
[:CmdPrepareUriList, ['prepare', 'uri-list']],
[:CmdPrepareSessionList, ['prepare', 'session-list']],
[:CmdPrepareSelfEditorAccount, ['prepare', 'self-editor-account']],
[:CmdPrepareSubList, ['prepare', 'sub-list']],
[:CmdCapture, ['capture']],
[:CmdCompareAgain, ['compare', 'again']],
[:CmdCompare, ['compare']],
[:CmdDisplay, ['display']]
]
def initialize(args)
COMMANDS.each do |cmd|
cmd_args = cmd[1]
matching_args = args.take(cmd_args.size)
remaining_args = args.drop(cmd_args.size)
if cmd_args == matching_args
@cmd_instance = Object.const_get(cmd[0]).new(remaining_args)
return
end
end
complain("Arguments not valid: #{args.join(' ')}\nValid choices are #{format_cmds}")
end
def format_cmds()
"\n #{COMMANDS.map {|c| c[1].join(' ') }.join("\n ")}"
end
def run()
@cmd_instance.run()
end
end
#
# ---------------------------------------------------------
# MAIN ROUTINE
# ---------------------------------------------------------
#
begin
Vivosnap.new(ARGV).run
rescue UserInputError
puts
puts $!
puts
end