From da0cf858a4c335dad175d08dede425ebad9eaa8d Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 25 Oct 2024 17:27:36 +0200 Subject: [PATCH] refactor: Replace root_config initialization with config.root usage --- src/commands/mapping_create.cr | 42 +++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/commands/mapping_create.cr b/src/commands/mapping_create.cr index 8b8999f..0d22953 100644 --- a/src/commands/mapping_create.cr +++ b/src/commands/mapping_create.cr @@ -5,12 +5,48 @@ module GX::Commands def initialize(@config : GX::Config) # FIXME @config.load_from_env @config.load_from_file - @file_system_manager = FileSystemManager.new(@config) end def execute - # FIXME: implement - puts "mapping create yo!" + # Assuming create_args is passed to this command with necessary details + create_args = @config.create_args + + # Validate required arguments + if create_args[:name].empty? || create_args[:path].empty? + raise ArgumentError.new("Name and path are required to create a mapping.") + end + + # Create the appropriate filesystem config based on the type + filesystem_config = case create_args[:type] + when "gocryptfs" + GX::Models::GocryptfsConfig.new( + name: create_args[:name], + path: create_args[:path], + encrypted_path: create_args[:encrypted_path] + ) + when "sshfs" + GX::Models::SshfsConfig.new( + name: create_args[:name], + path: create_args[:path], + remote_user: create_args[:remote_user], + remote_host: create_args[:remote_host], + remote_path: create_args[:remote_path], + remote_port: create_args[:remote_port] + ) + when "httpdirfs" + GX::Models::HttpdirfsConfig.new( + name: create_args[:name], + path: create_args[:path], + url: create_args[:url] + ) + else + raise ArgumentError.new("Unsupported mapping type: #{create_args[:type]}") + end + + # Append the new filesystem config to the root config + @config.root.try &.filesystems << filesystem_config + + puts "Mapping '#{create_args[:name]}' created and added to configuration successfully." end def self.handles_mode