Class: NewRelic::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/new_relic/command.rb
Defined Under Namespace
Classes: CommandFailure, Deployments, Install
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(command_line_args) ⇒ Command
Returns a new instance of Command.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/new_relic/command.rb', line 27
def initialize(command_line_args)
if Hash === command_line_args
command_line_args.each do | key, value |
instance_variable_set "@#{key}", value.to_s if value
end
else
@options = options do | opts |
opts.on("-h", "Show this help") { raise CommandFailure, opts.to_s }
end
@leftover = @options.parse(command_line_args)
end
rescue OptionParser::ParseError => e
raise CommandFailure.new(e.message, @options)
end
|
Instance Attribute Details
#leftover ⇒ Object
Returns the value of attribute leftover.
9
10
11
|
# File 'lib/new_relic/command.rb', line 9
def leftover
@leftover
end
|
Class Method Details
.inherited(subclass) ⇒ Object
45
46
47
|
# File 'lib/new_relic/command.rb', line 45
def self.inherited(subclass)
@commands << subclass
end
|
.run ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/new_relic/command.rb', line 52
def self.run
@command_names = @commands.map{ |c| c.command }
= []
options = ARGV.options do |opts|
script_name = File.basename($0)
if script_name =~ /newrelic_cmd$/
$stdout.puts "warning: the 'newrelic_cmd' script has been renamed 'newrelic'"
script_name = 'newrelic'
end
opts.banner = "Usage: #{script_name} [ #{ @command_names.join(" | ")} ] [options]"
opts.separator "use '#{script_name} <command> -h' to see detailed command options"
opts
end
= options.order!
command = .shift
command = 'deployments' if command =~ /deploy/
if command.nil?
STDERR.puts options
elsif !@command_names.include?(command)
STDERR.puts "Unrecognized command: #{command}"
STDERR.puts options
else
command_class = @commands.find{ |c| c.command == command}
command_class.new().run
end
rescue OptionParser::InvalidOption => e
raise NewRelic::Command::CommandFailure, e.message
end
|
Instance Method Details
#err(message) ⇒ Object
23
24
25
|
# File 'lib/new_relic/command.rb', line 23
def err(message)
STDERR.puts message
end
|
#info(message) ⇒ Object
19
20
21
|
# File 'lib/new_relic/command.rb', line 19
def info(message)
STDOUT.puts message
end
|