Class: NewRelic::Cli::Install
- Defined in:
- lib/new_relic/cli/commands/install.rb
Constant Summary collapse
- NO_LICENSE_KEY =
'<PASTE LICENSE KEY HERE>'
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Use -h to see options.
-
#dest_dir ⇒ Object
readonly
Use -h to see options.
-
#generated_for_user ⇒ Object
readonly
Use -h to see options.
-
#license_key ⇒ Object
readonly
Use -h to see options.
-
#quiet ⇒ Object
readonly
Use -h to see options.
-
#src_file ⇒ Object
readonly
Use -h to see options.
Attributes inherited from Command
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(command_line_args = {}) ⇒ Install
constructor
A new instance of Install.
- #run ⇒ Object
Methods inherited from Command
Constructor Details
#initialize(command_line_args = {}) ⇒ Install
Returns a new instance of Install.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/new_relic/cli/commands/install.rb', line 23 def initialize(command_line_args = {}) @dest_dir = nil super(command_line_args) if @dest_dir.nil? # Install a newrelic.yml file into the local config directory. if File.directory?('config') @dest_dir = 'config' else @dest_dir = '.' end end @license_key ||= NO_LICENSE_KEY @app_name ||= @leftover.join(' ') @agent_version = NewRelic::VERSION::STRING raise CommandFailure.new('Application name required.', @options) unless @app_name && @app_name.size > 0 end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.
Will throw CommandFailed exception if there’s any error.
22 23 24 |
# File 'lib/new_relic/cli/commands/install.rb', line 22 def app_name @app_name end |
#dest_dir ⇒ Object (readonly)
Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.
Will throw CommandFailed exception if there’s any error.
22 23 24 |
# File 'lib/new_relic/cli/commands/install.rb', line 22 def dest_dir @dest_dir end |
#generated_for_user ⇒ Object (readonly)
Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.
Will throw CommandFailed exception if there’s any error.
22 23 24 |
# File 'lib/new_relic/cli/commands/install.rb', line 22 def generated_for_user @generated_for_user end |
#license_key ⇒ Object (readonly)
Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.
Will throw CommandFailed exception if there’s any error.
22 23 24 |
# File 'lib/new_relic/cli/commands/install.rb', line 22 def license_key @license_key end |
#quiet ⇒ Object (readonly)
Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.
Will throw CommandFailed exception if there’s any error.
22 23 24 |
# File 'lib/new_relic/cli/commands/install.rb', line 22 def quiet @quiet end |
#src_file ⇒ Object (readonly)
Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.
Will throw CommandFailed exception if there’s any error.
22 23 24 |
# File 'lib/new_relic/cli/commands/install.rb', line 22 def src_file @src_file end |
Class Method Details
.command ⇒ Object
12 |
# File 'lib/new_relic/cli/commands/install.rb', line 12 def self.command; 'install'; end |
Instance Method Details
#content ⇒ Object
65 66 67 68 69 |
# File 'lib/new_relic/cli/commands/install.rb', line 65 def content @src_file ||= File.(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'newrelic.yml')) template = File.read(@src_file) ERB.new(template).result(binding) end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/new_relic/cli/commands/install.rb', line 40 def run dest_file = File.(@dest_dir + '/newrelic.yml') if File.exist?(dest_file) && !@force raise NewRelic::Cli::Command::CommandFailure, 'newrelic.yml file already exists. Use --force flag to overwrite.' end File.open(dest_file, 'w') { |out| out.puts(content) } puts <<~EOF unless quiet Installed a default configuration file at #{dest_file}. EOF puts <<~EOF unless quiet || @license_key != NO_LICENSE_KEY To monitor your application in production mode, sign up for an account at www.newrelic.com, and replace the newrelic.yml file with the one you receive upon registration. EOF puts <<~EOF unless quiet Visit support.newrelic.com if you are experiencing installation issues. EOF end |