Class: Papertrail::CliJoinGroup
- Inherits:
-
Object
- Object
- Papertrail::CliJoinGroup
show all
- Includes:
- CliHelpers
- Defined in:
- lib/papertrail/cli_join_group.rb
Instance Method Summary
collapse
Methods included from CliHelpers
#find_configfile, #load_configfile, #parse_time, #set_min_max_time!, #symbolize_keys
Instance Method Details
#run ⇒ Object
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
58
59
60
61
|
# File 'lib/papertrail/cli_join_group.rb', line 11
def run
options = {
:configfile => nil,
:token => ENV['PAPERTRAIL_API_TOKEN'],
}
if configfile = find_configfile
configfile_options = load_configfile(configfile)
options.merge!(configfile_options)
end
OptionParser.new do |opts|
opts.banner = "papertrail-join-group"
opts.on("-h", "--help", "Show usage") do |v|
puts opts
exit
end
opts.on("-c", "--configfile PATH", "Path to config (~/.papertrail.yml)") do |v|
options[:configfile] = File.expand_path(v)
end
opts.on("-s", "--system SYSTEM", "Name of system to add to group") do |v|
options[:system] = v
end
opts.on("-g", "--group GROUP", "Name of group to join") do |v|
options[:group] = v
end
opts.separator usage
end.parse!
if options[:configfile]
configfile_options = load_configfile(options[:configfile])
options.merge!(configfile_options)
end
raise OptionParser::MissingArgument, 'system' if options[:system].nil?
raise OptionParser::MissingArgument, 'group' if options[:group].nil?
connection = Papertrail::Connection.new(options)
if connection.join_group(options[:system], options[:group])
exit 0
end
exit 1
rescue OptionParser::ParseError => e
puts "Error: #{e}"
puts usage
exit 1
end
|
#usage ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/papertrail/cli_join_group.rb', line 63
def usage
<<-EOF
Usage:
papertrail-join-group [-s system] [-g group] [-c papertrail.yml]
Example:
papertrail-join-group -s mymachine -g mygroup
EOF
end
|