Skip to content

Enhance Atmos CLI: Add Support for Custom Base Path and Config Paths #1091

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 118 commits into from
Apr 10, 2025

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Feb 25, 2025

what

  • Introduce global command-line flags (--base-path, --config, and --config-path) to the Atmos CLI tool.
  • If the --config or --config-path flag is changed, Atmos will load configurations only from the specified paths.
  • The --config flag specifies an Atmos configuration file, such as dir1/config.yaml or dir2/config2.yaml, updating cli_config_path to dir1;dir2
  • The --config-path flag specifies directories containing Atmos configuration files. files names should be one of (atmos.yaml, .atmos.yaml,atmos.yml, .atmos.yml), such as dir3/ or dir4/, updating cli_config_path to dir3;dir4
  • Support handling multiple configurations from both --config and --config-path simultaneously
  • Integrate embedded configuration support

why

  • These changes make it easier to override Atmos settings dynamically—especially useful in automation, such as CI/CD pipelines and local testing. By specifying --config or --config-path
  • Load alternate configurations without modifying global settings.
  • Apply environment-specific settings for testing or deployments.
  • Manage multiple Atmos configurations .
  • Simplify local development by easily switching between configuration setups.

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added persistent CLI flags (--base-path, --config, and --config-path) to allow users to specify a custom project base path and define multiple configuration files and directories.
    • Introduced an embedded configuration file for flexible log management.
    • Enhanced command-line argument processing for improved configurability.
  • Bug Fixes

    • Removed the --config flag from the command-line interface, streamlining configuration management.
  • Documentation

    • Updated help outputs and configuration guides to reflect the new flags and explain the configuration load order.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7557d71 and d12b369.

📒 Files selected for processing (1)
  • cmd/validate_editorconfig.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: golangci-lint
cmd/validate_editorconfig.go

[failure] 56-56:
SA1019: u.LogErrorAndExit is deprecated: Use log.Fatal instead. This function will be removed in a future release. LogErrorAndExit logs errors to std.Error and exits with an error code.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (2)
cmd/validate_editorconfig.go (2)

53-59: Added proper flag handling for --config.

This code correctly retrieves the --config flag values when changed and assigns them to the configFilePaths variable, which addresses the previous review comment from samtholiya. This is a key improvement that aligns with the PR's goal of supporting custom config paths.

🧰 Tools
🪛 GitHub Check: golangci-lint

[failure] 56-56:
SA1019: u.LogErrorAndExit is deprecated: Use log.Fatal instead. This function will be removed in a future release. LogErrorAndExit logs errors to std.Error and exits with an error code.


188-203:

❓ Verification inconclusive

Verify --config flag is properly defined globally.

I notice that the --config flag isn't defined in addPersistentFlags, which suggests it's now defined at a more global level (likely in cmd/root.go). This aligns with the PR's goal of adding global CLI flags.

Run this script to confirm the flag is defined globally:


🏁 Script executed:

#!/bin/bash
# Check if the --config flag is defined in root.go
echo "Checking if --config flag is defined in root.go:"
grep -n "config.*StringSlice" cmd/root.go

Length of output: 150


Global '--config' flag: Manual Verification Required

Our initial automated check (searching for a StringSlice definition in cmd/root.go) didn’t yield any results for the --config flag. This may mean the flag is defined elsewhere or using a different type (e.g. with StringVar). Please double-check manually that the flag is properly defined at the global level as intended by the PR’s goal.

  • Verify in cmd/root.go (or any other global flag initialization file) that the --config flag is defined.
  • Confirm that its definition uses the appropriate flag type (e.g. StringVar vs. StringSlice).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
cmd/validate_editorconfig.go (1)

72-72: 🛠️ Refactor suggestion

Replace deprecated u.LogErrorAndExit calls

Multiple instances of the deprecated u.LogErrorAndExit function remain in this file. According to the static analysis, this function is deprecated and will be removed in a future release.

Replace all instances with the recommended log.Fatal or the more graceful error handling approach:

-u.LogErrorAndExit(err)
+log.Error("Operation failed", "error", err)
+os.Exit(1)

Also applies to: 104-104, 110-110, 151-151, 156-156

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d12b369 and 21b07b9.

📒 Files selected for processing (1)
  • cmd/validate_editorconfig.go (2 hunks)
🧰 Additional context used
🪛 GitHub Check: golangci-lint
cmd/validate_editorconfig.go

[failure] 57-57:
deep-exit: calls to log.Fatal only in main() or init() functions

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Summary
🔇 Additional comments (1)
cmd/validate_editorconfig.go (1)

8-8: Good update to charmbracelet/log library

This import change aligns with modern logging practices in the codebase.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (2)
cmd/validate_editorconfig.go (2)

73-73: 🛠️ Refactor suggestion

Replace deprecated function with recommended alternative.

The u.LogErrorAndExit function is deprecated according to previous static analysis warnings.

-	u.LogErrorAndExit(err)
+	log.Error("Failed to save config", "error", err)
+	os.Exit(1)

Note that this still has the issue of calling os.Exit outside of main/init. Consider refactoring the overall error handling approach across the file.


105-106: 💡 Verification agent

🧩 Analysis chain

Update all instances of deprecated error handling.

There are multiple instances of u.LogErrorAndExit that should be updated consistently with the same error handling pattern you choose.

Also applies to: 111-112, 152-153, 157-158


🏁 Script executed:

#!/bin/bash
# Find all instances of u.LogErrorAndExit in this file
echo "Instances of deprecated u.LogErrorAndExit in validate_editorconfig.go:"
grep -n "u.LogErrorAndExit" cmd/validate_editorconfig.go

# Check if any custom error handling helpers exist in the codebase
echo -e "\nLooking for potential error handling helpers:"
grep -r "func LogError" --include="*.go" pkg/

Length of output: 906


Consistent error handling update required
Please replace all instances of u.LogErrorAndExit in cmd/validate_editorconfig.go with a unified error handling approach (for example, using u.LogError along with an explicit exit if needed). This update applies to the calls on lines 73, 105, 111, 152, and 157. Make sure the new pattern is used across the codebase wherever applicable.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21b07b9 and 4b47622.

📒 Files selected for processing (1)
  • cmd/validate_editorconfig.go (2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.64.8)
cmd/validate_editorconfig.go

[error] 8-8: import "github.com/charmbracelet/log" imported without alias but must be with alias "log" according to config

(importas)

🪛 GitHub Check: golangci-lint
cmd/validate_editorconfig.go

[failure] 8-8:
import "github.com/charmbracelet/log" imported without alias but must be with alias "log" according to config


[failure] 58-58:
deep-exit: calls to os.Exit only in main() or init() functions

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (1)
cmd/validate_editorconfig.go (1)

54-61: Good implementation of config flag handling.

The code correctly checks for the --config flag and retrieves values as a string slice, properly addressing the previous review comment about getting flag values to configFilePaths.

🧰 Tools
🪛 GitHub Check: golangci-lint

[failure] 58-58:
deep-exit: calls to os.Exit only in main() or init() functions

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/validate_editorconfig.go (1)

53-58: Good solution for flag value handling.

You've addressed the previous feedback by correctly retrieving the --config flag value and populating the configFilePaths variable. The code checks for flag presence and safely handles the lookup.

Consider using the more direct GetStringSlice method instead of manual string splitting:

if cmd.Flags().Changed("config") {
-	config := cmd.Flags().Lookup("config")
-	if config != nil {
-		configFilePaths = strings.Split(config.Value.String(), ",")
-	}
+	configFiles, err := cmd.Flags().GetStringSlice("config")
+	if err != nil {
+		u.LogErrorMsg(fmt.Sprintf("Failed to get config flag values: %v", err))
+		return
+	}
+	configFilePaths = configFiles
}

This provides better error handling and ensures correct parsing based on the flag's defined type.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b47622 and 6992777.

📒 Files selected for processing (1)
  • cmd/validate_editorconfig.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
cmd/validate_editorconfig.go (2)
Learnt from: samtholiya
PR: cloudposse/atmos#1077
File: pkg/downloader/custom_github_detector.go:0-0
Timestamp: 2025-04-03T12:14:28.671Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log` according to the project's import alias configuration.
Learnt from: samtholiya
PR: cloudposse/atmos#1077
File: pkg/downloader/custom_github_detector_test.go:0-0
Timestamp: 2025-04-03T12:14:38.761Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log`, not `clog`.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary

@mergify mergify bot removed the triage Needs triage label Apr 10, 2025
@aknysh aknysh merged commit 48a6b1f into main Apr 10, 2025
56 checks passed
@aknysh aknysh deleted the DEV-2790 branch April 10, 2025 16:19
Copy link

These changes were released in v1.171.0.

@coderabbitai coderabbitai bot mentioned this pull request Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes) size/xl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants