Skip to content

Commit 0949f9f

Browse files
nieomylniejalabtom
andauthored
fix: Add project flag back again for sloctl replay (#193)
#177 removed default project flags, unfortunately we missed the `sloctl replay` command which also relied on them. This PR brings the `-p` flag back for `sloctl replay` command. --------- Co-authored-by: Tomek Labuk <[email protected]>
1 parent affd6ec commit 0949f9f

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

internal/apply.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func (r *RootCmd) NewApplyCmd() *cobra.Command {
5252
registerFileFlag(cmd, true, &apply.definitionPaths)
5353
registerDryRunFlag(cmd, &apply.dryRun)
5454
registerAutoConfirmationFlag(cmd, &apply.autoConfirm)
55-
registerProjectFlag(cmd, &apply.project)
55+
cmd.Flags().StringVarP(&apply.project, "project", "p", "",
56+
`Assigns the provided Project to the resources if no Project is defined in the object's definition.`)
5657

5758
const (
5859
replayFlagName = "replay"

internal/delete.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func (r *RootCmd) NewDeleteCmd() *cobra.Command {
5151
registerFileFlag(cmd, false, &deleteCmd.definitionPaths)
5252
registerDryRunFlag(cmd, &deleteCmd.dryRun)
5353
registerAutoConfirmationFlag(cmd, &deleteCmd.autoConfirm)
54-
registerProjectFlag(cmd, &deleteCmd.project)
54+
cmd.Flags().StringVarP(&deleteCmd.project, "project", "p", "",
55+
`Assigns the provided Project to the resources if no Project is defined in the object's definition.`)
5556

5657
// register all subcommands for delete
5758
for _, def := range []struct {
@@ -129,7 +130,8 @@ func newSubcommand(
129130
},
130131
}
131132
if objectKindSupportsProjectFlag(kind) {
132-
registerProjectFlag(sc, &deleteCmd.project)
133+
sc.Flags().StringVarP(&deleteCmd.project, "project", "p", "",
134+
`Specifies the Project from which to delete the resources. If not provided, the default Project will be used.`)
133135
}
134136
registerDryRunFlag(sc, &deleteCmd.dryRun)
135137
return sc

internal/flags.go

-10
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ func objectKindSupportsProjectFlag(kind manifest.Kind) bool {
7777
return ok
7878
}
7979

80-
func registerProjectFlag(cmd *cobra.Command, storeIn *string) {
81-
cmd.Flags().StringVarP(storeIn, "project", "p", "",
82-
`List the requested object(s) which belong to the specified Project (name).`)
83-
}
84-
85-
func registerAllProjectsFlag(cmd *cobra.Command, storeIn *bool) {
86-
cmd.Flags().BoolVarP(storeIn, "all-projects", "A", false,
87-
`List the requested object(s) across all projects.`)
88-
}
89-
9080
var labelSupportingKinds = map[manifest.Kind]struct{}{
9181
manifest.KindProject: {},
9282
manifest.KindService: {},

internal/get.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ To get more details in output use one of the available flags.`,
9898
subCmd.Extender(sc)
9999
}
100100
if objectKindSupportsProjectFlag(subCmd.Kind) {
101-
registerProjectFlag(sc, &get.project)
102-
registerAllProjectsFlag(sc, &get.allProjects)
101+
sc.Flags().StringVarP(&get.project, "project", "p", "",
102+
`List the requested object(s) which belong to the specified Project (name).`)
103+
sc.Flags().BoolVarP(&get.allProjects, "all-projects", "A", false,
104+
`List the requested object(s) across all projects.`)
103105
}
104106
if objectKindSupportsLabelsFlag(subCmd.Kind) {
105107
registerLabelsFlag(sc, &get.labels)

internal/replay.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type ReplayCmd struct {
3333
from TimeValue
3434
configPaths []string
3535
sloName string
36+
project string
3637
}
3738

3839
//go:embed replay_example.sh
@@ -54,13 +55,20 @@ func (r *RootCmd) NewReplayCmd() *cobra.Command {
5455
"Importing data takes time: Replay for a single SLO may take several minutes up to an hour. " +
5556
"During that time, the command keeps on running, periodically checking the status of Replay. " +
5657
"If you cancel the program execution at any time, the current Replay in progress will not be revoked.",
57-
Example: replayExample,
58-
Args: replay.arguments,
59-
PersistentPreRun: func(cmd *cobra.Command, args []string) { replay.client = r.GetClient() },
60-
RunE: func(cmd *cobra.Command, args []string) error { return replay.Run(cmd) },
58+
Example: replayExample,
59+
Args: replay.arguments,
60+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
61+
replay.client = r.GetClient()
62+
if replay.project != "" {
63+
replay.client.Config.Project = replay.project
64+
}
65+
},
66+
RunE: func(cmd *cobra.Command, args []string) error { return replay.Run(cmd) },
6167
}
6268

6369
registerFileFlag(cmd, false, &replay.configPaths)
70+
cmd.Flags().StringVarP(&replay.project, "project", "p", "",
71+
`Specifies the Project for the SLOs you want to Replay.`)
6472
cmd.Flags().Var(&replay.from, "from", "Sets the start of Replay time window.")
6573

6674
return cmd

0 commit comments

Comments
 (0)