Skip to content

feat: Save default appmap.yml #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ cache:
- yarn

rbenv:
- 2.5
- 2.6
- 2.7
- 3.0
Expand Down
2 changes: 2 additions & 0 deletions appmap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Gem::Specification.new do |spec|
spec.authors = ['Kevin Gilpin']
spec.email = ['[email protected]']

spec.required_ruby_version = '>= 2.6.0'

spec.summary = %q{Record the operation of a Ruby program, using the AppLand 'AppMap' format.}
spec.homepage = AppMap::URL
spec.license = 'MIT'
Expand Down
30 changes: 18 additions & 12 deletions lib/appmap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,28 +338,34 @@ def load_from_file(config_file_name)
AppMap uses this file to customize its behavior. For example, you can use
the 'packages' setting to indicate which local file paths and dependency
gems you want to include in the AppMap. Since you haven't provided specific
settings, the appmap gem will try and guess some reasonable defaults.
To suppress this message, create the file:

#{Pathname.new(config_file_name).expand_path}

Here are the default settings that will be used in the meantime. You can
copy and paste this example to start your appmap.yml.
settings, the appmap gem will use these default options:
MISSING_FILE_MSG
{}
end

load(config_data).tap do |config|
config_yaml = {
{
'name' => config.name,
'packages' => config.packages.select{|p| p.path}.map do |pkg|
{ 'path' => pkg.path }
end,
'exclude' => []
}.compact
unless config_present
warn Util.color(YAML.dump(config_yaml), :magenta)
warn logo.()
}.compact.tap do |config_yaml|
unless config_present
warn Util.color(YAML.dump(config_yaml), :magenta)
dirname = Pathname.new(config_file_name).dirname.expand_path
if Dir.exists?(dirname) && File.writable?(dirname)
warn Util.color(<<~CONFIG_FILE_MSG, :magenta)
This file will be saved to #{Pathname.new(config_file_name).expand_path},
where you can customize it.
CONFIG_FILE_MSG
File.write(config_file_name, YAML.dump(config_yaml))
end
warn Util.color(<<~CONFIG_FILE_MSG, :magenta)
For more information, see https://appmap.io/docs/reference/appmap-ruby.html#configuration
CONFIG_FILE_MSG
warn logo.()
end
end
end
end
Expand Down
22 changes: 18 additions & 4 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@
end
end

context do
context 'missing config file' do
before { FileUtils.mkdir_p 'tmp' }
let(:warnings) { @warnings ||= [] }
let(:warning) { warnings.join }
before do
expect(AppMap::Config).to receive(:warn).at_least(1) { |msg| warnings << msg }
end
it 'prints a warning and uses a default config' do
expect(AppMap::Config).to receive(:warn).at_least(1) { |msg| warnings << msg }

config = AppMap::Config.load_from_file 'no/such/file'
expect(config.to_h).to eq(YAML.load(<<~CONFIG))
:name: appmap-ruby
Expand All @@ -150,5 +150,19 @@
CONFIG
expect(warning).to include('NOTICE: The AppMap config file no/such/file was not found!')
end
describe 'writeable dir' do
it 'saves the guessed config' do
expect(File).to receive(:write).with("tmp/appmap.yml", instance_of(String))

AppMap::Config.load_from_file 'tmp/appmap.yml'
end
end
describe 'non-writeable dir' do
it 'does not save the guessed config' do
File.stub(:write).and_raise "Unexpected File.write"

config = AppMap::Config.load_from_file '/no/such/appmap.yml'
end
end
end
end