Skip to content

Commit c441ab9

Browse files
committed
Rename environment flag to context in deploy and diff commands
- Replace --environment with --context in deploy and diff commands - Update all CLI help text and error messages to use context terminology - Update all tests to use new flag names and terminology - Update documentation examples and architecture diagrams - Update project documentation to consistently use context terminology - Breaking change: users must update from --environment to --context Both deploy and diff commands now use consistent --context flag for specifying deployment contexts, providing a more generic and unified CLI interface.
1 parent d54e495 commit c441ab9

File tree

11 files changed

+110
-116
lines changed

11 files changed

+110
-116
lines changed

AGENTS.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ For straightforward command handlers and basic functionality:
145145
```go
146146
func TestFunctionName_Scenario_ExpectedBehaviour(t *testing.T) {
147147
// Arrange - Set up test data and mocks
148-
148+
149149
// Act - Execute the function under test
150-
150+
151151
// Assert - Verify the expected behaviour
152152
require.NoError(t, err)
153153
assert.Equal(t, expected, actual)
@@ -160,17 +160,17 @@ func TestCloudFormationService_CreateStack_Success(t *testing.T) {
160160
// Arrange
161161
mockCF := &mockCloudFormationAPI{}
162162
service := NewCloudFormationService(mockCF)
163-
163+
164164
expectedInput := &cloudformation.CreateStackInput{
165165
StackName: aws.String("test-stack"),
166166
}
167-
167+
168168
mockCF.On("CreateStack", mock.AnythingOfType("*context.emptyCtx"), expectedInput).
169169
Return(&cloudformation.CreateStackOutput{}, nil)
170-
170+
171171
// Act
172172
result, err := service.CreateStack(context.Background(), "test-stack", template)
173-
173+
174174
// Assert
175175
require.NoError(t, err)
176176
assert.NotNil(t, result)
@@ -279,18 +279,13 @@ All tests must pass before merging. Run `make commit-check` before committing.
279279

280280
### YAML Configuration
281281
- Stack definitions in YAML format
282-
- Environment-specific parameter overrides
282+
- Context-specific parameter overrides
283283
- Template path resolution
284284
- Dependency declarations with `depends_on`
285285

286286
### File Structure Expectations
287287
```
288288
stackaroo.yml # Main configuration
289-
environments/
290-
dev/
291-
parameters.yml # Dev environment parameters
292-
prod/
293-
parameters.yml # Prod environment parameters
294289
templates/
295290
vpc.yml # CloudFormation templates
296291
app.yml
@@ -318,7 +313,7 @@ make version # Show version info
318313

319314
### Supported Platforms
320315
- Linux (AMD64, ARM64)
321-
- macOS (AMD64, ARM64)
316+
- macOS (AMD64, ARM64)
322317
- Windows (AMD64, ARM64)
323318

324319
## Common Development Tasks
@@ -423,4 +418,4 @@ Must be presented to and approved by the driver before committing.
423418
### Logging
424419
- Use structured logging for AWS operations
425420
- Include request IDs for AWS API calls
426-
- Log stack names and operations clearly
421+
- Log stack names and operations clearly

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ A command-line tool for managing AWS CloudFormation stacks as code.
77
Stackaroo simplifies CloudFormation stack management by providing:
88

99
- **Declarative Configuration**: Define your stacks and parameters in YAML files
10-
- **Environment Management**: Deploy the same templates across multiple environments
10+
- **Environment Management**: Deploy the same templates across multiple contexts
1111
- **Change Preview**: See exactly what changes will be made before deployment
1212
- **Template Validation**: Validate CloudFormation templates before deployment
1313
- **Stack Lifecycle**: Deploy, update, delete, and monitor stack status
14-
- **Parameter Management**: Organize parameters by environment and stack
14+
- **Parameter Management**: Organize parameters by context and stack
1515

1616
## Features
1717

1818
### Environment Management
19-
- Deploy the same templates across multiple environments
20-
- Environment-specific parameter overrides
21-
- Different AWS regions and profiles per environment
19+
- Deploy the same templates across multiple contexts
20+
- Different AWS regions and parameters per context
2221

2322
### Dependency Management
2423

@@ -43,7 +42,7 @@ Stackaroo simplifies CloudFormation stack management by providing:
4342

4443
### Real-time Event Streaming
4544

46-
- **Change Preview Before Deployment**: See exactly what will change before applying
45+
- See exactly what will change before applying
4746
- Live CloudFormation events during deployment operations
4847
- See resource creation, updates, and completion status in real-time
4948
- Smart detection of create vs update operations

cmd/deploy.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
var (
19-
environmentName string
19+
contextName string
2020
// deployer can be injected for testing
2121
deployer deploy.Deployer
2222
)
@@ -39,8 +39,8 @@ ChangeSets to provide accurate previews including:
3939
For new stacks, the command proceeds directly with stack creation.
4040
4141
Examples:
42-
stackaroo deploy vpc --environment dev
43-
stackaroo deploy app --environment prod
42+
stackaroo deploy vpc --context dev
43+
stackaroo deploy app --context prod
4444
4545
The preview shows the same detailed diff information as 'stackaroo diff' but
4646
automatically proceeds with deployment after displaying the changes.`,
@@ -49,12 +49,12 @@ automatically proceeds with deployment after displaying the changes.`,
4949
stackName := args[0]
5050
ctx := context.Background()
5151

52-
// Environment must be provided
53-
if environmentName == "" {
54-
return fmt.Errorf("--environment must be specified")
52+
// Context must be provided
53+
if contextName == "" {
54+
return fmt.Errorf("--context must be specified")
5555
}
5656

57-
return deployWithConfig(ctx, stackName, environmentName)
57+
return deployWithConfig(ctx, stackName, contextName)
5858
},
5959
}
6060

@@ -82,13 +82,13 @@ func SetDeployer(d deploy.Deployer) {
8282
}
8383

8484
// deployWithConfig handles deployment using configuration file
85-
func deployWithConfig(ctx context.Context, stackName, environmentName string) error {
85+
func deployWithConfig(ctx context.Context, stackName, contextName string) error {
8686
// Create configuration provider and resolver
8787
provider := file.NewDefaultProvider()
8888
resolver := resolve.NewStackResolver(provider)
8989

9090
// Resolve stack and all its dependencies
91-
resolved, err := resolver.Resolve(ctx, environmentName, []string{stackName})
91+
resolved, err := resolver.Resolve(ctx, contextName, []string{stackName})
9292
if err != nil {
9393
return fmt.Errorf("failed to resolve stack dependencies: %w", err)
9494
}
@@ -117,16 +117,16 @@ func deployWithConfig(ctx context.Context, stackName, environmentName string) er
117117
return fmt.Errorf("error deploying stack %s: %w", stackName, err)
118118
}
119119

120-
fmt.Printf("Successfully deployed stack %s in environment %s\n", stackName, environmentName)
120+
fmt.Printf("Successfully deployed stack %s in context %s\n", stackName, contextName)
121121
}
122122

123123
return nil
124124
}
125125

126126
func init() {
127127
rootCmd.AddCommand(deployCmd)
128-
deployCmd.Flags().StringVar(&environmentName, "environment", "", "deployment environment")
129-
if err := deployCmd.MarkFlagRequired("environment"); err != nil {
130-
panic(fmt.Sprintf("failed to mark environment flag as required: %v", err))
128+
deployCmd.Flags().StringVar(&contextName, "context", "", "deployment context")
129+
if err := deployCmd.MarkFlagRequired("context"); err != nil {
130+
panic(fmt.Sprintf("failed to mark context flag as required: %v", err))
131131
}
132132
}

cmd/deploy_test.go

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

56-
func TestDeployCommand_HasEnvironmentFlag(t *testing.T) {
57-
// Test that deploy command has a --environment flag
56+
func TestDeployCommand_HasContextFlag(t *testing.T) {
57+
// Test that deploy command has a --context flag
5858
deployCmd := findCommand(rootCmd, "deploy")
5959
assert.NotNil(t, deployCmd)
6060

61-
// Check that --environment flag exists
62-
environmentFlag := deployCmd.Flags().Lookup("environment")
63-
assert.NotNil(t, environmentFlag, "deploy command should have --environment flag")
64-
assert.Equal(t, "environment", environmentFlag.Name)
61+
// Check that --context flag exists
62+
contextFlag := deployCmd.Flags().Lookup("context")
63+
assert.NotNil(t, contextFlag, "deploy command should have --context flag")
64+
assert.Equal(t, "context", contextFlag.Name)
6565
}
6666

67-
func TestDeployCommand_RequiresEnvironment(t *testing.T) {
68-
// Test that deploy command requires --environment flag
67+
func TestDeployCommand_RequiresContext(t *testing.T) {
68+
// Test that deploy command requires --context flag
6969

7070
// Mock deployer that shouldn't be called
7171
mockDeployer := &MockDeployer{}
@@ -74,12 +74,12 @@ func TestDeployCommand_RequiresEnvironment(t *testing.T) {
7474
SetDeployer(mockDeployer)
7575
defer SetDeployer(oldDeployer)
7676

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

8080
err := rootCmd.Execute()
81-
assert.Error(t, err, "deploy command should require --environment flag")
82-
assert.Contains(t, err.Error(), "required flag(s) \"environment\" not set")
81+
assert.Error(t, err, "deploy command should require --context flag")
82+
assert.Contains(t, err.Error(), "required flag(s) \"context\" not set")
8383

8484
// Verify no deployer calls were made
8585
mockDeployer.AssertExpectations(t)
@@ -129,7 +129,7 @@ stacks:
129129
}()
130130

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

134134
// Execute the command - should return error
135135
err = rootCmd.Execute()
@@ -224,12 +224,12 @@ stacks:
224224
}()
225225

226226
// First deployment should succeed
227-
rootCmd.SetArgs([]string{"deploy", "stack-1", "--environment", "test"})
227+
rootCmd.SetArgs([]string{"deploy", "stack-1", "--context", "test"})
228228
err = rootCmd.Execute()
229229
assert.NoError(t, err, "first deployment should succeed")
230230

231231
// Second deployment should fail
232-
rootCmd.SetArgs([]string{"deploy", "stack-2", "--environment", "test"})
232+
rootCmd.SetArgs([]string{"deploy", "stack-2", "--context", "test"})
233233
err = rootCmd.Execute()
234234
assert.Error(t, err, "second deployment should fail")
235235
assert.Contains(t, err.Error(), "second deployment failed", "error should contain expected message")
@@ -294,7 +294,7 @@ stacks:
294294

295295
// Set up mock deployer that expects config-resolved values
296296
mockDeployer := &MockDeployer{}
297-
// Expect Stack with resolved parameters from dev environment
297+
// Expect Stack with resolved parameters from dev context
298298
mockDeployer.On("DeployStack", mock.Anything, mock.MatchedBy(func(stack *model.Stack) bool {
299299
return stack.Name == "vpc" &&
300300
stack.Parameters["VpcCidr"] == "10.1.0.0/16" &&
@@ -316,8 +316,8 @@ stacks:
316316
require.NoError(t, err)
317317
}()
318318

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

322322
err = rootCmd.Execute()
323323
assert.NoError(t, err, "deploy command should execute successfully with config")
@@ -402,7 +402,7 @@ stacks:
402402

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

407407
err = rootCmd.Execute()
408408
assert.NoError(t, err, "deploy should succeed")
@@ -478,7 +478,7 @@ stacks:
478478
}()
479479

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

483483
err = rootCmd.Execute()
484484
assert.NoError(t, err, "deploy should succeed")
@@ -501,11 +501,11 @@ contexts:
501501
stacks:
502502
- name: vpc
503503
template: templates/vpc.yaml
504-
504+
505505
- name: database
506506
template: templates/db.yaml
507507
depends_on: [vpc]
508-
508+
509509
- name: app
510510
template: templates/app.yaml
511511
depends_on: [database]

cmd/diff.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
)
1717

1818
var (
19-
diffEnvironmentName string
20-
diffTemplateOnly bool
21-
diffParametersOnly bool
22-
diffTagsOnly bool
23-
diffFormat string
19+
diffContextName string
20+
diffTemplateOnly bool
21+
diffParametersOnly bool
22+
diffTagsOnly bool
23+
diffFormat string
2424
// differ can be injected for testing
2525
differ diff.Differ
2626
)
@@ -40,26 +40,26 @@ the current configuration. It compares:
4040
• Resource-level changes (when possible via AWS ChangeSets)
4141
4242
Examples:
43-
stackaroo diff vpc --environment dev # Show all changes
44-
stackaroo diff vpc --environment prod --template # Template diff only
45-
stackaroo diff vpc --environment dev --parameters # Parameter diff only
46-
stackaroo diff vpc --environment dev --format json # JSON output`,
43+
stackaroo diff vpc --context dev # Show all changes
44+
stackaroo diff vpc --context prod --template # Template diff only
45+
stackaroo diff vpc --context dev --parameters # Parameter diff only
46+
stackaroo diff vpc --context dev --format json # JSON output`,
4747
Args: cobra.ExactArgs(1),
4848
RunE: func(cmd *cobra.Command, args []string) error {
4949
stackName := args[0]
5050
ctx := context.Background()
5151

52-
// Environment must be provided
53-
if diffEnvironmentName == "" {
54-
return fmt.Errorf("--environment must be specified")
52+
// Context must be provided
53+
if diffContextName == "" {
54+
return fmt.Errorf("--context must be specified")
5555
}
5656

5757
// Validate format option
5858
if diffFormat != "text" && diffFormat != "json" {
5959
return fmt.Errorf("--format must be 'text' or 'json'")
6060
}
6161

62-
return diffWithConfig(ctx, stackName, diffEnvironmentName)
62+
return diffWithConfig(ctx, stackName, diffContextName)
6363
},
6464
}
6565

@@ -87,13 +87,13 @@ func SetDiffer(d diff.Differ) {
8787
}
8888

8989
// diffWithConfig handles diff using configuration file
90-
func diffWithConfig(ctx context.Context, stackName, environmentName string) error {
90+
func diffWithConfig(ctx context.Context, stackName, contextName string) error {
9191
// Create configuration provider and resolver
9292
provider := file.NewDefaultProvider()
9393
resolver := resolve.NewStackResolver(provider)
9494

9595
// Resolve stack and all its dependencies
96-
resolved, err := resolver.Resolve(ctx, environmentName, []string{stackName})
96+
resolved, err := resolver.Resolve(ctx, contextName, []string{stackName})
9797
if err != nil {
9898
return fmt.Errorf("failed to resolve stack dependencies: %w", err)
9999
}
@@ -134,9 +134,9 @@ func diffWithConfig(ctx context.Context, stackName, environmentName string) erro
134134
// Set exit code based on whether changes were found
135135
if result.HasChanges() {
136136
// Exit with code 1 if changes detected (similar to git diff)
137-
fmt.Printf("\nChanges detected for stack %s in environment %s\n", stackName, environmentName)
137+
fmt.Printf("\nChanges detected for stack %s in context %s\n", stackName, contextName)
138138
} else {
139-
fmt.Printf("\nNo changes detected for stack %s in environment %s\n", stackName, environmentName)
139+
fmt.Printf("\nNo changes detected for stack %s in context %s\n", stackName, contextName)
140140
}
141141

142142
return nil
@@ -146,9 +146,9 @@ func init() {
146146
rootCmd.AddCommand(diffCmd)
147147

148148
// Required flags
149-
diffCmd.Flags().StringVar(&diffEnvironmentName, "environment", "", "deployment environment")
150-
if err := diffCmd.MarkFlagRequired("environment"); err != nil {
151-
panic(fmt.Sprintf("failed to mark environment flag as required: %v", err))
149+
diffCmd.Flags().StringVar(&diffContextName, "context", "", "deployment context")
150+
if err := diffCmd.MarkFlagRequired("context"); err != nil {
151+
panic(fmt.Sprintf("failed to mark context flag as required: %v", err))
152152
}
153153

154154
// Optional flags for filtering diff output

0 commit comments

Comments
 (0)