Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add project flag back again for sloctl replay #193

Merged
merged 9 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading