Sha256: fc1c07fc08a76052975f21c696f32165b04efa166d147bf00e04a2cd237f02f2

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'fileutils'
require 'appmap/service/guesser'
require 'appmap/util'

module AppMap
  module Command
    module AgentSetup
      InitStruct = Struct.new(:config_file)

      class Init < InitStruct
        def perform
          if File.exist?(config_file)
            puts AppMap::Util.color(%(The AppMap config file #{config_file} already exists.), :magenta)
            return
          end

          ensure_directory_exists

          config = {
            'name' => Service::Guesser.guess_name,
            'packages' => Service::Guesser.guess_paths.map { |path| { 'path' => path } }
          }
          content = YAML.dump(config).gsub("---\n", '')

          File.write(config_file, content)
          puts AppMap::Util.color(
            %(The following AppMap config file #{config_file} has been created:),
            :green
          )
          puts content
        end

        private

        def ensure_directory_exists
          dirname = File.dirname(config_file)
          FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
appmap-0.56.0 lib/appmap/command/agent_setup/init.rb
appmap-0.55.0 lib/appmap/command/agent_setup/init.rb
appmap-0.54.4 lib/appmap/command/agent_setup/init.rb
appmap-0.54.3 lib/appmap/command/agent_setup/init.rb
appmap-0.54.2 lib/appmap/command/agent_setup/init.rb
appmap-0.54.1 lib/appmap/command/agent_setup/init.rb
appmap-0.54.0 lib/appmap/command/agent_setup/init.rb
appmap-0.53.0 lib/appmap/command/agent_setup/init.rb
appmap-0.52.1 lib/appmap/command/agent_setup/init.rb
appmap-0.52.0 lib/appmap/command/agent_setup/init.rb