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
|
# File 'lib/termdump/command.rb', line 9
def initialize args
@args = OpenStruct.new(:stdout => false, :action => :load, :list => false,
:session => '', :exclude => false)
OptionParser.new do |opts|
opts.banner = "Usage: termdump [options] [session]"
opts.on('-i', '--init', 'initialize configure interactively') {
@args.action = :init
}
opts.on('-e', '--edit [session]', 'edit session') do |name|
@args.action = :edit
name.nil? ? @args.list = true : @args.session = name
end
opts.on('-d', '--delete [session]', 'delete session') do |name|
@args.action = :delete
name.nil? ? @args.list = true : @args.session = name
end
opts.on('-s', '--save [session]', 'save session') do |name|
@args.action = :save
name.nil? ? @args.list = true : @args.session = name
end
opts.on_tail('--stdout', 'print dump result to stdout while saving a session') {
@args.stdout = true
}
opts.on_tail('--exclude', 'exclude current pty while saving a session') {
@args.exclude = true
}
opts.on_tail('-l', '--list', 'list all sessions') {
@args.list = true
}
opts.on_tail('-v', '--version', 'print version') do
puts VERSION
exit 0
end
opts.parse! args
if @args.action == :load
args.size > 0 ? @args.session = args[0] : @args.list = true
end
if @args.stdout || @args.exclude
if @args.action != :save
puts opts.help
exit 1
end
end
end
end
|