Class: NewRelic::Cli::Install

Inherits:
Command
  • Object
show all
Defined in:
lib/new_relic/cli/commands/install.rb

Constant Summary collapse

NO_LICENSE_KEY =
'<PASTE LICENSE KEY HERE>'

Instance Attribute Summary collapse

Attributes inherited from Command

#leftover

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#err, #info, inherited, run

Constructor Details

#initialize(command_line_args = {}) ⇒ Install

Returns a new instance of Install.

Raises:



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_nameObject (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_dirObject (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_userObject (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_keyObject (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

#quietObject (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_fileObject (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

.commandObject



12
# File 'lib/new_relic/cli/commands/install.rb', line 12

def self.command; 'install'; end

Instance Method Details

#contentObject



65
66
67
68
69
# File 'lib/new_relic/cli/commands/install.rb', line 65

def content
  @src_file ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'newrelic.yml'))
  template = File.read(@src_file)
  ERB.new(template).result(binding)
end

#runObject



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.expand_path(@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