Skip to content

Commit

Permalink
--force flag added to mimic Tanzu scheduler plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
norman-abramovitz committed Jun 13, 2024
1 parent ac3a149 commit 04111f7
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 4 deletions.
7 changes: 7 additions & 0 deletions commands/delete-call-schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
// cf delete-call-schedule CALL-NAME SCHEDULE-GUID
func DeleteCallSchedule(services *core.Services, args []string) {
var forceFlag bool
var promptFlag bool

flags := pflag.NewFlagSet("delete-call-schedule", pflag.ExitOnError)
flags.BoolVarP(&forceFlag, "force", "f", false, "Force call schedule deletion without confirmation")
flags.BoolVarP(&promptFlag, "prompt", "p", false, "Allow call schedule deletion with confirmation")
flags.MarkHidden("prompt")
flags.Parse(args)
args = flags.Args()

Expand All @@ -38,6 +41,10 @@ func DeleteCallSchedule(services *core.Services, args []string) {
return
}

if promptFlag && !forceFlag && !services.UI.ConfirmDelete("call schedule", name + " " + scheduleGUID) {
return;
}

err = client.DeleteCallSchedule(services.Client, call, scheduleGUID)
if err != nil {
fmt.Println("Could not delete schedule", scheduleGUID)
Expand Down
7 changes: 7 additions & 0 deletions commands/delete-call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
// cf delete-call CALL-NAME
func DeleteCall(services *core.Services, args []string) {
var forceFlag bool
var promptFlag bool

flags := pflag.NewFlagSet("delete-call", pflag.ExitOnError)
flags.BoolVarP(&forceFlag, "force", "f", false, "Force call deletion without confirmation")
flags.BoolVarP(&promptFlag, "prompt", "p", false, "Allow call deletion with confirmation")
flags.MarkHidden("prompt")
flags.Parse(args)
args = flags.Args()

Expand All @@ -37,6 +40,10 @@ func DeleteCall(services *core.Services, args []string) {
return
}

if promptFlag && !forceFlag && !services.UI.ConfirmDeleteWithAssociations("call", name) {
return;
}

err = client.DeleteCall(services.Client, call)
if err != nil {
fmt.Println("Could not delete call: " + err.Error())
Expand Down
7 changes: 7 additions & 0 deletions commands/delete-job-schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
// cf delete-job-schedule JOB-NAME SCHEDULE-GUID
func DeleteJobSchedule(services *core.Services, args []string) {
var forceFlag bool
var promptFlag bool

flags := pflag.NewFlagSet("delete-job-schedule", pflag.ExitOnError)
flags.BoolVarP(&forceFlag, "force", "f", false, "Force job schedule deletion without confirmation")
flags.BoolVarP(&promptFlag, "prompt", "p", false, "Allow job schedule deletion with confirmation")
flags.MarkHidden("prompt")
flags.Parse(args)

args = flags.Args()
Expand All @@ -38,6 +41,10 @@ func DeleteJobSchedule(services *core.Services, args []string) {
return
}

if promptFlag && !forceFlag && !services.UI.ConfirmDelete("job schedule", name + " " + scheduleGUID) {
return;
}

err = client.DeleteJobSchedule(services.Client, job, scheduleGUID)
if err != nil {
fmt.Println("Could not delete schedule", scheduleGUID)
Expand Down
7 changes: 7 additions & 0 deletions commands/delete-job.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
// cf delete-job JOB-NAME
func DeleteJob(services *core.Services, args []string) {
var forceFlag bool
var promptFlag bool

flags := pflag.NewFlagSet("delete-job", pflag.ExitOnError)
flags.BoolVarP(&forceFlag, "force", "f", false, "Force job deletion without confirmation")
flags.BoolVarP(&promptFlag, "prompt", "p", false, "Allow job deletion with confirmation")
flags.MarkHidden("prompt")
flags.Parse(args)
args = flags.Args()

Expand All @@ -37,6 +40,10 @@ func DeleteJob(services *core.Services, args []string) {
return
}

if promptFlag && !forceFlag && !services.UI.ConfirmDeleteWithAssociations("job", name) {
return;
}

err = client.DeleteJob(services.Client, job)
if err != nil {
fmt.Println("Could not delete job: " + err.Error())
Expand Down
2 changes: 2 additions & 0 deletions core/services.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package core

import "code.cloudfoundry.org/cli/plugin"
import "code.cloudfoundry.org/cli/cf/terminal"

type Services struct {
CLI plugin.CliConnection
Client *Driver
UI terminal.UI
}
23 changes: 22 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.3

require (
code.cloudfoundry.org/cli v7.1.0+incompatible
code.cloudfoundry.org/cli v0.0.0-20240404012325-79ae2fb5db92
github.com/cloudfoundry-community/ocf-scheduler v1.0.0
github.com/cloudfoundry/cf-acceptance-tests v1.9.1-0.20220405181007-a6e4d7ae3b33
github.com/cloudfoundry/cf-test-helpers v1.0.1-0.20220329060630-a1956dba8c6c
Expand All @@ -17,21 +17,42 @@ require (
)

require (
code.cloudfoundry.org/bytefmt v0.0.0-20230612151507-41ef4d1f67a4 // indirect
code.cloudfoundry.org/tlsconfig v0.0.0-20230612153104-23c0622de227 // indirect
github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/charlievieth/fs v0.0.3 // indirect
github.com/cloudfoundry/bosh-cli v6.4.1+incompatible // indirect
github.com/cloudfoundry/bosh-utils v0.0.390 // indirect
github.com/cppforlife/go-patch v0.1.0 // indirect
github.com/ess/debuggable v1.0.0 // indirect
github.com/ess/dry v1.0.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/vito/go-interact v0.0.0-20171111012221-fa338ed9e9ec // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 04111f7

Please sign in to comment.