From 01804f113978232f1a7eefe5c03c79b37b7b5e37 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 10 Dec 2024 23:58:38 +0100 Subject: [PATCH] feat: add configuration saving functionality to MappingCreate command --- src/commands/mapping_create.cr | 2 ++ src/config.cr | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index d2882d1..e03db95 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -4,12 +4,14 @@ # Copyright © 2024 Glenn Y. Rolland require "./abstract_command" +require "../models/filesystem_factory" module GX::Commands class MappingCreate < AbstractCommand def initialize(@config : GX::Config) @config.load_from_env @config.load_from_file + @config.save_to_file end def execute diff --git a/src/config.cr b/src/config.cr index cc7f43e..182c186 100644 --- a/src/config.cr +++ b/src/config.cr @@ -120,5 +120,15 @@ module GX end @root = root end + + def save_to_file + return if @path.nil? + if @path + File.write(@path.to_s, @root.to_yaml) + else + Log.error { "Configuration path is nil, cannot save configuration." } + end + Log.info { "Configuration saved to #{@path}" } + end end end