Skip to content

Commit c1531f6

Browse files
authored
Enhance environment flag handling in CLI (#10)
- Updated the environment flag description to include 'production' for clarity. - Added normalization for the 'production' environment to be treated as 'prod' in command execution. - Ensures downstream commands receive the correct environment value, improving consistency in environment handling.
1 parent 6109f10 commit c1531f6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/cli/root.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/furiatona/azctl/internal/config"
89
"github.com/furiatona/azctl/internal/logging"
@@ -39,7 +40,7 @@ func Execute(ctx context.Context, args []string) error {
3940
// Global persistent flags
4041
root.PersistentFlags().String("envfile", ".env", "Path to .env file (optional)")
4142
root.PersistentFlags().String("env", "",
42-
"Environment name (dev, staging, prod) - determines .env file and Azure App Config scope")
43+
"Environment name (dev, staging, production) - determines .env file and Azure App Config scope")
4344
root.PersistentFlags().Bool("verbose", false, "Enable verbose logging")
4445
root.PersistentFlags().String("log-level", "info", "Log level (debug, info, warn, error)")
4546
root.PersistentFlags().String("log-format", "text", "Log format (text, json)")
@@ -67,6 +68,11 @@ func Execute(ctx context.Context, args []string) error {
6768

6869
envfile, _ := cmd.Flags().GetString("envfile")
6970
env, _ := cmd.Flags().GetString("env")
71+
if strings.EqualFold(env, "production") {
72+
env = "prod"
73+
// Update flag value so downstream commands see normalized env
74+
_ = cmd.Flags().Set("env", env)
75+
}
7076

7177
// If environment is specified, use environment-specific .env file
7278
if env != "" && envfile == ".env" {

0 commit comments

Comments
 (0)