Skip to content

Commit

Permalink
fix: Add project flag back again for sloctl replay (#193)
Browse files Browse the repository at this point in the history
#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 <89924840+labtom@users.noreply.github.com>
  • Loading branch information
nieomylnieja and labtom authored Aug 20, 2024
1 parent affd6ec commit 0949f9f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion internal/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func (r *RootCmd) NewApplyCmd() *cobra.Command {
registerFileFlag(cmd, true, &apply.definitionPaths)
registerDryRunFlag(cmd, &apply.dryRun)
registerAutoConfirmationFlag(cmd, &apply.autoConfirm)
registerProjectFlag(cmd, &apply.project)
cmd.Flags().StringVarP(&apply.project, "project", "p", "",
`Assigns the provided Project to the resources if no Project is defined in the object's definition.`)

const (
replayFlagName = "replay"
Expand Down
6 changes: 4 additions & 2 deletions internal/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (r *RootCmd) NewDeleteCmd() *cobra.Command {
registerFileFlag(cmd, false, &deleteCmd.definitionPaths)
registerDryRunFlag(cmd, &deleteCmd.dryRun)
registerAutoConfirmationFlag(cmd, &deleteCmd.autoConfirm)
registerProjectFlag(cmd, &deleteCmd.project)
cmd.Flags().StringVarP(&deleteCmd.project, "project", "p", "",
`Assigns the provided Project to the resources if no Project is defined in the object's definition.`)

// register all subcommands for delete
for _, def := range []struct {
Expand Down Expand Up @@ -129,7 +130,8 @@ func newSubcommand(
},
}
if objectKindSupportsProjectFlag(kind) {
registerProjectFlag(sc, &deleteCmd.project)
sc.Flags().StringVarP(&deleteCmd.project, "project", "p", "",
`Specifies the Project from which to delete the resources. If not provided, the default Project will be used.`)
}
registerDryRunFlag(sc, &deleteCmd.dryRun)
return sc
Expand Down
10 changes: 0 additions & 10 deletions internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ func objectKindSupportsProjectFlag(kind manifest.Kind) bool {
return ok
}

func registerProjectFlag(cmd *cobra.Command, storeIn *string) {
cmd.Flags().StringVarP(storeIn, "project", "p", "",
`List the requested object(s) which belong to the specified Project (name).`)
}

func registerAllProjectsFlag(cmd *cobra.Command, storeIn *bool) {
cmd.Flags().BoolVarP(storeIn, "all-projects", "A", false,
`List the requested object(s) across all projects.`)
}

var labelSupportingKinds = map[manifest.Kind]struct{}{
manifest.KindProject: {},
manifest.KindService: {},
Expand Down
6 changes: 4 additions & 2 deletions internal/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ To get more details in output use one of the available flags.`,
subCmd.Extender(sc)
}
if objectKindSupportsProjectFlag(subCmd.Kind) {
registerProjectFlag(sc, &get.project)
registerAllProjectsFlag(sc, &get.allProjects)
sc.Flags().StringVarP(&get.project, "project", "p", "",
`List the requested object(s) which belong to the specified Project (name).`)
sc.Flags().BoolVarP(&get.allProjects, "all-projects", "A", false,
`List the requested object(s) across all projects.`)
}
if objectKindSupportsLabelsFlag(subCmd.Kind) {
registerLabelsFlag(sc, &get.labels)
Expand Down
16 changes: 12 additions & 4 deletions internal/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ReplayCmd struct {
from TimeValue
configPaths []string
sloName string
project string
}

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

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

return cmd
Expand Down

0 comments on commit 0949f9f

Please sign in to comment.