Skip to content

Fix --configDir option to set GABS config directory for all files with centralized path management#47

Merged
pardeike merged 4 commits intomainfrom
copilot/fix-239e5b3f-b456-42af-a429-3410e9ede698
Sep 15, 2025
Merged

Fix --configDir option to set GABS config directory for all files with centralized path management#47
pardeike merged 4 commits intomainfrom
copilot/fix-239e5b3f-b456-42af-a429-3410e9ede698

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 15, 2025

The --configDir option was defined and parsed but not fully implemented. While it affected the main GABS configuration file, bridge configuration files were still created in the default ~/.gabs/ directory, making the option only partially functional.

Problem

# This would only move config.json but leave bridge files in ~/.gabs/
gabs games --configDir /custom/path list
gabs server --configDir /custom/path

The LoadGamesConfig() function in internal/config/games.go used the custom directory, but bridge file creation in the MCP server always used the hardcoded ~/.gabs/ path, creating an inconsistent configuration layout.

Solution

Modified the configuration system to properly respect the --configDir option for all GABS configuration files and centralized configuration directory handling:

Centralized Configuration Path Management:

  • Created ConfigPaths system: New ConfigPaths type that provides a single source of truth for all configuration directory resolution
  • Single initialization: NewConfigPaths(baseDir) creates path resolver with custom or default ~/.gabs/ directory
  • Unified methods: GetMainConfigPath(), GetGameDir(), GetBridgeConfigPath() provide consistent path resolution
  • Directory management: EnsureGameDir() and EnsureBaseDir() handle directory creation consistently

Refactored Implementation:

  • Removed scattered functions: Eliminated getGamesConfigPath() and getConfigDir() functions that duplicated directory logic
  • Updated all config code: All configuration operations now use the centralized ConfigPaths system
  • Consistent behavior: Bridge creation, cleanup, and main config operations all respect the same base directory

Enhanced Functionality:

  • MCP Server integration: Added configDir field and updated CleanupBridgeConfig() to use centralized paths
  • Bridge creation: Modified startGame() to pass configDir to WriteBridgeJSON()
  • Backward compatibility: When --configDir is not specified, uses default ~/.gabs/ directory

Usage

# Use custom config directory for ALL files
gabs games --configDir /custom/config list
gabs games --configDir /custom/config add minecraft  
gabs server --configDir /custom/config

# Directory structure:
# /custom/config/
# ├── config.json              (main GABS config)
# └── minecraft/
#     └── bridge.json           (game bridge config)

# Default behavior unchanged
gabs games list  # Uses ~/.gabs/config.json and ~/.gabs/*/bridge.json
gabs server      # Uses ~/.gabs/ for all files

Testing

Added comprehensive tests to verify:

  • Custom config directory path construction works correctly for both main and bridge configs
  • Config loading and saving works with custom directories
  • Bridge file creation and cleanup respects custom directories
  • Default behavior is preserved when no custom directory is specified
  • ConfigPaths system provides consistent path resolution
  • All existing tests continue to pass

The fix ensures that --configDir now properly moves the entire GABS configuration base directory as originally intended, with a clean, centralized architecture that eliminates duplicate directory resolution logic and provides consistent configuration management across all GABS components.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: pardeike <853584+pardeike@users.noreply.github.com>
Copilot AI changed the title [WIP] The --configDir option should set the main gabs config files location. I think its not used. Also, there might be the wrong description for it but i am not sure (it should say its related to the gabs config and not to the bridge config) Fix --configDir option to set main GABS config files location Sep 15, 2025
Copilot AI requested a review from pardeike September 15, 2025 00:31
@pardeike
Copy link
Copy Markdown
Owner

@copilot Great work. One question remains (just to be sure): —configDir affects the directory of the GABS config file but that also contains the game bridge files. Will the —configDir option also affect where the bridge files are created - it’s what I think is logical: it moves the whole base directory.

Co-authored-by: pardeike <853584+pardeike@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot Great work. One question remains (just to be sure): —configDir affects the directory of the GABS config file but that also contains the game bridge files. Will the —configDir option also ...

You're absolutely correct! The --configDir option now affects both the main GABS config file AND the bridge files - it moves the whole base directory as expected.

Previously, while config.json used the custom directory, bridge files were still created in the default ~/.gabs/ location. I've fixed this by:

  1. Adding configDir support to the MCP Server
  2. Updating bridge file creation to use the custom directory
  3. Fixing the cleanup process to respect the custom directory

Now when you use --configDir /custom/path, you get:

/custom/path/
├── config.json        (main config)
└── minecraft/
    └── bridge.json     (bridge config)

Fixed in commit 73fa3b4 with comprehensive test coverage to ensure it works correctly.

Copilot AI changed the title Fix --configDir option to set main GABS config files location Fix --configDir option to set GABS config directory for all files Sep 15, 2025
@pardeike
Copy link
Copy Markdown
Owner

@copilot maybe I am wrong but from your last changes I get the impression that the handling of the base configuration directory is not cleanly implemented. In my book this should be one central place to ask for the path and the default is ~/.gabs or the overwritten value of —configDir. Then all the code calls the central method that returns the actual path. Maybe the implementation is already clean but I am not sure

…ystem

Co-authored-by: pardeike <853584+pardeike@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot maybe I am wrong but from your last changes I get the impression that the handling of the base configuration directory is not cleanly implemented. In my book this should be one central place...

You're absolutely right! The configuration directory handling was scattered across multiple functions. I've now centralized it into a single ConfigPaths system.

Before (scattered approach):

  • getGamesConfigPath() in games.go for main config
  • getConfigDir() in bridgecfg.go for bridge configs
  • Manual path construction in stdio_server.go

After (centralized approach):

  • Single ConfigPaths type that handles ALL configuration paths
  • NewConfigPaths(baseDir) - One place to resolve base directory (custom or ~/.gabs)
  • All code now calls the centralized methods: GetMainConfigPath(), GetBridgeConfigPath(), etc.

This makes the implementation much cleaner and ensures consistent behavior across all configuration operations. Fixed in commit 5047495.

Copilot AI changed the title Fix --configDir option to set GABS config directory for all files Fix --configDir option to set GABS config directory for all files with centralized path management Sep 15, 2025
@pardeike pardeike marked this pull request as ready for review September 15, 2025 00:56
@pardeike pardeike merged commit 25dcea0 into main Sep 15, 2025
6 checks passed
@pardeike pardeike deleted the copilot/fix-239e5b3f-b456-42af-a429-3410e9ede698 branch September 15, 2025 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants