Skip to content

Commit 4205978

Browse files
committed
Change --context flag to --environment
- Replace --context CLI flag with --environment for better user experience - Update variable names from contextName to environmentName - Preserve internal config system using 'context' terminology - Update all test cases to use new --environment flag - Update example documentation and usage comments Breaking change: Users must now use --environment instead of --context
1 parent 444dc1d commit 4205978

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

cmd/deploy.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
var (
18-
contextName string
18+
environmentName string
1919
// deployer can be injected for testing
2020
deployer Deployer
2121
)
@@ -34,12 +34,12 @@ var deployCmd = &cobra.Command{
3434
stackName := args[0]
3535
ctx := context.Background()
3636

37-
// Context must be provided
38-
if contextName == "" {
39-
return fmt.Errorf("--context must be specified")
37+
// Environment must be provided
38+
if environmentName == "" {
39+
return fmt.Errorf("--environment must be specified")
4040
}
4141

42-
return deployWithConfig(ctx, stackName, contextName)
42+
return deployWithConfig(ctx, stackName, environmentName)
4343
},
4444
}
4545

@@ -67,13 +67,13 @@ func SetDeployer(d Deployer) {
6767
}
6868

6969
// deployWithConfig handles deployment using configuration file
70-
func deployWithConfig(ctx context.Context, stackName, contextName string) error {
70+
func deployWithConfig(ctx context.Context, stackName, environmentName string) error {
7171
// Create configuration provider and resolver
7272
provider := file.NewDefaultProvider()
7373
resolver := resolve.NewStackResolver(provider)
7474

7575
// Resolve stack and all its dependencies
76-
resolved, err := resolver.Resolve(ctx, contextName, []string{stackName})
76+
resolved, err := resolver.Resolve(ctx, environmentName, []string{stackName})
7777
if err != nil {
7878
return fmt.Errorf("failed to resolve stack dependencies: %w", err)
7979
}
@@ -102,16 +102,16 @@ func deployWithConfig(ctx context.Context, stackName, contextName string) error
102102
return fmt.Errorf("error deploying stack %s: %w", stackName, err)
103103
}
104104

105-
fmt.Printf("Successfully deployed stack %s in context %s\n", stackName, contextName)
105+
fmt.Printf("Successfully deployed stack %s in environment %s\n", stackName, environmentName)
106106
}
107107

108108
return nil
109109
}
110110

111111
func init() {
112112
rootCmd.AddCommand(deployCmd)
113-
deployCmd.Flags().StringVar(&contextName, "context", "", "deployment context (environment)")
114-
if err := deployCmd.MarkFlagRequired("context"); err != nil {
115-
panic(fmt.Sprintf("failed to mark context flag as required: %v", err))
113+
deployCmd.Flags().StringVar(&environmentName, "environment", "", "deployment environment")
114+
if err := deployCmd.MarkFlagRequired("environment"); err != nil {
115+
panic(fmt.Sprintf("failed to mark environment flag as required: %v", err))
116116
}
117117
}

cmd/deploy_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ func TestDeployCommand_AcceptsStackName(t *testing.T) {
4747
assert.NotNil(t, deployCmd.Args, "deploy command should have Args validation set")
4848
}
4949

50-
func TestDeployCommand_HasContextFlag(t *testing.T) {
51-
// Test that deploy command has a --context flag
50+
func TestDeployCommand_HasEnvironmentFlag(t *testing.T) {
51+
// Test that deploy command has a --environment flag
5252
deployCmd := findCommand(rootCmd, "deploy")
5353
assert.NotNil(t, deployCmd)
5454

55-
// Check that --context flag exists
56-
contextFlag := deployCmd.Flags().Lookup("context")
57-
assert.NotNil(t, contextFlag, "deploy command should have --context flag")
58-
assert.Equal(t, "context", contextFlag.Name)
55+
// Check that --environment flag exists
56+
environmentFlag := deployCmd.Flags().Lookup("environment")
57+
assert.NotNil(t, environmentFlag, "deploy command should have --environment flag")
58+
assert.Equal(t, "environment", environmentFlag.Name)
5959
}
6060

61-
func TestDeployCommand_RequiresContext(t *testing.T) {
62-
// Test that deploy command requires --context flag
61+
func TestDeployCommand_RequiresEnvironment(t *testing.T) {
62+
// Test that deploy command requires --environment flag
6363

6464
// Mock deployer that shouldn't be called
6565
mockDeployer := &MockDeployer{}
@@ -68,12 +68,12 @@ func TestDeployCommand_RequiresContext(t *testing.T) {
6868
SetDeployer(mockDeployer)
6969
defer SetDeployer(oldDeployer)
7070

71-
// Execute without context flag - should fail
71+
// Execute without environment flag - should fail
7272
rootCmd.SetArgs([]string{"deploy", "test-stack"})
7373

7474
err := rootCmd.Execute()
75-
assert.Error(t, err, "deploy command should require --context flag")
76-
assert.Contains(t, err.Error(), "required flag(s) \"context\" not set")
75+
assert.Error(t, err, "deploy command should require --environment flag")
76+
assert.Contains(t, err.Error(), "required flag(s) \"environment\" not set")
7777

7878
// Verify no deployer calls were made
7979
mockDeployer.AssertExpectations(t)
@@ -123,7 +123,7 @@ stacks:
123123
}()
124124

125125
// Execute the root command with deploy subcommand and arguments
126-
rootCmd.SetArgs([]string{"deploy", "test-stack", "--context", "test"})
126+
rootCmd.SetArgs([]string{"deploy", "test-stack", "--environment", "test"})
127127

128128
// Execute the command - should return error
129129
err = rootCmd.Execute()
@@ -218,12 +218,12 @@ stacks:
218218
}()
219219

220220
// First deployment should succeed
221-
rootCmd.SetArgs([]string{"deploy", "stack-1", "--context", "test"})
221+
rootCmd.SetArgs([]string{"deploy", "stack-1", "--environment", "test"})
222222
err = rootCmd.Execute()
223223
assert.NoError(t, err, "first deployment should succeed")
224224

225225
// Second deployment should fail
226-
rootCmd.SetArgs([]string{"deploy", "stack-2", "--context", "test"})
226+
rootCmd.SetArgs([]string{"deploy", "stack-2", "--environment", "test"})
227227
err = rootCmd.Execute()
228228
assert.Error(t, err, "second deployment should fail")
229229
assert.Contains(t, err.Error(), "second deployment failed", "error should contain expected message")
@@ -288,7 +288,7 @@ stacks:
288288

289289
// Set up mock deployer that expects config-resolved values
290290
mockDeployer := &MockDeployer{}
291-
// Expect ResolvedStack with resolved parameters from dev context
291+
// Expect ResolvedStack with resolved parameters from dev environment
292292
mockDeployer.On("DeployStack", mock.Anything, mock.MatchedBy(func(resolvedStack *resolve.ResolvedStack) bool {
293293
return resolvedStack.Name == "vpc" &&
294294
resolvedStack.Parameters["VpcCidr"] == "10.1.0.0/16" &&
@@ -310,8 +310,8 @@ stacks:
310310
require.NoError(t, err)
311311
}()
312312

313-
// Execute deploy command with context flag
314-
rootCmd.SetArgs([]string{"deploy", "vpc", "--context", "dev"})
313+
// Execute deploy command with environment flag
314+
rootCmd.SetArgs([]string{"deploy", "vpc", "--environment", "dev"})
315315

316316
err = rootCmd.Execute()
317317
assert.NoError(t, err, "deploy command should execute successfully with config")
@@ -396,7 +396,7 @@ stacks:
396396

397397
// This should resolve dependencies and deploy: vpc → database → app
398398
// But current implementation will only deploy app
399-
rootCmd.SetArgs([]string{"deploy", "app", "--context", "test"})
399+
rootCmd.SetArgs([]string{"deploy", "app", "--environment", "test"})
400400

401401
err = rootCmd.Execute()
402402
assert.NoError(t, err, "deploy should succeed")
@@ -472,7 +472,7 @@ stacks:
472472
}()
473473

474474
// Deploy app - should trigger resolver to deploy vpc → database → app
475-
rootCmd.SetArgs([]string{"deploy", "app", "--context", "test"})
475+
rootCmd.SetArgs([]string{"deploy", "app", "--environment", "test"})
476476

477477
err = rootCmd.Execute()
478478
assert.NoError(t, err, "deploy should succeed")

examples/simple-vpc/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ The `stackaroo.yaml` file defines:
5252

5353
3. **Deploy to development**:
5454
```bash
55-
../../stackaroo deploy vpc --context dev
55+
../../stackaroo deploy vpc --environment dev
5656
```
5757

5858
4. **Deploy to staging**:
5959
```bash
60-
../../stackaroo deploy vpc --context staging
60+
../../stackaroo deploy vpc --environment staging
6161
```
6262

6363
5. **Deploy to production** (requires production account access):
6464
```bash
65-
../../stackaroo deploy vpc --context prod
65+
../../stackaroo deploy vpc --environment prod
6666
```
6767

6868
## What Gets Deployed
@@ -87,16 +87,16 @@ Each deployment creates:
8787

8888
Check the status of your deployments:
8989
```bash
90-
../../stackaroo status vpc --context dev
90+
../../stackaroo status vpc --environment dev
9191
```
9292

9393
## Cleanup
9494

9595
To remove the infrastructure:
9696
```bash
97-
../../stackaroo delete vpc --context dev
98-
../../stackaroo delete vpc --context staging
99-
../../stackaroo delete vpc --context prod
97+
../../stackaroo delete vpc --environment dev
98+
../../stackaroo delete vpc --environment staging
99+
../../stackaroo delete vpc --environment prod
100100
```
101101

102102
## Learning Points

examples/simple-vpc/stackaroo.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ stacks:
6262
Monitoring: enabled
6363

6464
# Usage examples:
65-
# stackaroo deploy vpc --context dev # Deploy to dev environment
66-
# stackaroo deploy vpc --context prod # Deploy to production
67-
# stackaroo list --context staging # List stacks in staging
65+
# stackaroo deploy vpc --environment dev # Deploy to dev environment
66+
# stackaroo deploy vpc --environment prod # Deploy to production
67+
# stackaroo list --environment staging # List stacks in staging

0 commit comments

Comments
 (0)