Sha256: 44b82f6bd135cd5534a1b822eb4c9fe9621369fff530824d411c814d72d02fcb

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

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

module AppMap
  module Command
    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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
appmap-0.51.3 lib/appmap/command/init.rb
appmap-0.51.2 lib/appmap/command/init.rb