Skip to content

Commit 9f331d1

Browse files
authored
Add --exclude flag to CLI commands (#6340)
* add `--exclude` flag to cli commands * don't use `--exclude` for the remove command
1 parent 7e40fe8 commit 9f331d1

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

cmd/sst/deploy.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ var CmdDeploy = &cli.Command{
2929
"sst deploy --target MyComponent",
3030
"```",
3131
"",
32+
"Alternatively, exclude a specific component from the deploy.",
33+
"",
34+
"```bash frame=\"none\"",
35+
"sst deploy --exclude MyComponent",
36+
"```",
37+
"",
3238
"All the resources are deployed as concurrently as possible, based on their dependencies.",
3339
"For resources like your container images, sites, and functions; it first builds them and then deploys the generated assets.",
3440
"",
@@ -89,6 +95,14 @@ var CmdDeploy = &cli.Command{
8995
Long: "Only run it for the given component.",
9096
},
9197
},
98+
{
99+
Name: "exclude",
100+
Type: "string",
101+
Description: cli.Description{
102+
Short: "Exclude a component",
103+
Long: "Exclude the specified component from the operation.",
104+
},
105+
},
92106
{
93107
Name: "continue",
94108
Type: "bool",
@@ -126,6 +140,11 @@ var CmdDeploy = &cli.Command{
126140
target = strings.Split(c.String("target"), ",")
127141
}
128142

143+
exclude := []string{}
144+
if c.String("exclude") != "" {
145+
exclude = strings.Split(c.String("exclude"), ",")
146+
}
147+
129148
var wg errgroup.Group
130149
defer wg.Wait()
131150
out := make(chan interface{})
@@ -152,6 +171,7 @@ var CmdDeploy = &cli.Command{
152171
err = p.Run(c.Context, &project.StackInput{
153172
Command: "deploy",
154173
Target: target,
174+
Exclude: exclude,
155175
Dev: c.Bool("dev"),
156176
ServerPort: s.Port,
157177
Verbose: c.Bool("verbose"),

cmd/sst/diff.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ var CmdDiff = &cli.Command{
3939
"sst diff --target MyComponent",
4040
"```",
4141
"",
42+
"Alternatively, exclude a specific component from the diff.",
43+
"",
44+
"```bash frame=\"none\"",
45+
"sst diff --exclude MyComponent",
46+
"```",
47+
"",
4248
"By default, this compares to the last deploy of the given stage as it would be",
4349
"deployed using `sst deploy`. But if you are working in dev mode using `sst dev`,",
4450
"you can use the `--dev` flag.",
@@ -58,6 +64,14 @@ var CmdDiff = &cli.Command{
5864
Long: "Only run it for the given component.",
5965
},
6066
},
67+
{
68+
Name: "exclude",
69+
Type: "string",
70+
Description: cli.Description{
71+
Short: "Exclude a component",
72+
Long: "Exclude the specified component from the operation.",
73+
},
74+
},
6175
{
6276
Name: "dev",
6377
Type: "bool",
@@ -89,6 +103,11 @@ var CmdDiff = &cli.Command{
89103
target = strings.Split(c.String("target"), ",")
90104
}
91105

106+
exclude := []string{}
107+
if c.String("exclude") != "" {
108+
exclude = strings.Split(c.String("exclude"), ",")
109+
}
110+
92111
var wg errgroup.Group
93112
defer wg.Wait()
94113
outputs := []*apitype.ResOutputsEvent{}
@@ -121,6 +140,7 @@ var CmdDiff = &cli.Command{
121140
ServerPort: s.Port,
122141
Dev: c.Bool("dev"),
123142
Target: target,
143+
Exclude: exclude,
124144
Verbose: c.Bool("verbose"),
125145
})
126146
if err != nil {

cmd/sst/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,12 @@ var root = &cli.Command{
968968
"sst refresh --target MyComponent",
969969
"```",
970970
"",
971+
"Alternatively, exclude a specific component from the refresh.",
972+
"",
973+
"```bash frame=\"none\"",
974+
"sst refresh --exclude MyComponent",
975+
"```",
976+
"",
971977
"This is useful for cases where you want to ensure that your local state is in sync with your cloud provider. [Learn more about how state works](/docs/providers/#how-state-works).",
972978
}, "\n"),
973979
},
@@ -980,6 +986,14 @@ var root = &cli.Command{
980986
Long: "Only run it for the given component.",
981987
},
982988
},
989+
{
990+
Name: "exclude",
991+
Type: "string",
992+
Description: cli.Description{
993+
Short: "Exclude a component",
994+
Long: "Exclude the specified component from the operation.",
995+
},
996+
},
983997
},
984998
Run: CmdRefresh,
985999
},

cmd/sst/refresh.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ func CmdRefresh(c *cli.Cli) error {
2323
target = strings.Split(c.String("target"), ",")
2424
}
2525

26+
exclude := []string{}
27+
if c.String("exclude") != "" {
28+
exclude = strings.Split(c.String("exclude"), ",")
29+
}
30+
2631
var wg errgroup.Group
2732
defer wg.Wait()
2833
ui := ui.New(c.Context)
@@ -47,6 +52,7 @@ func CmdRefresh(c *cli.Cli) error {
4752
err = p.Run(c.Context, &project.StackInput{
4853
Command: "refresh",
4954
Target: target,
55+
Exclude: exclude,
5056
ServerPort: s.Port,
5157
Verbose: c.Bool("verbose"),
5258
})

pkg/project/run.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ func (p *Project) RunNext(ctx context.Context, input *StackInput) error {
344344
}
345345
}
346346

347+
if input.Exclude != nil {
348+
for _, item := range input.Exclude {
349+
index := slices.IndexFunc(completed.Resources, func(res apitype.ResourceV3) bool {
350+
return res.URN.Name() == item
351+
})
352+
if index == -1 {
353+
return util.NewReadableError(nil, fmt.Sprintf("Exclude target not found: %v", item))
354+
}
355+
args = append(args, "--exclude", string(completed.Resources[index].URN))
356+
}
357+
if len(input.Exclude) > 0 {
358+
args = append(args, "--exclude-dependents")
359+
}
360+
}
361+
347362
cmd := process.Command(pulumiPath, args...)
348363
process.Detach(cmd)
349364
cmd.Env = env

pkg/project/stack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type BuildFailedEvent struct {
1616
type StackInput struct {
1717
Command string
1818
Target []string
19+
Exclude []string
1920
ServerPort int
2021
Dev bool
2122
Verbose bool

0 commit comments

Comments
 (0)