Skip to content

Commit 4278167

Browse files
feat: added oauth delete command
1 parent 91451cd commit 4278167

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

cmd/oauth/delete.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package oauth
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/pterm/pterm"
7+
"github.com/urfave/cli/v2"
8+
9+
"github.com/NodeOps-app/createos-cli/internal/terminal"
10+
)
11+
12+
func newDeleteCommand() *cli.Command {
13+
return &cli.Command{
14+
Name: "delete",
15+
Usage: "Delete an OAuth client",
16+
ArgsUsage: "[client-id]",
17+
Flags: []cli.Flag{
18+
&cli.StringFlag{Name: "client", Usage: "OAuth client ID"},
19+
&cli.BoolFlag{Name: "force", Usage: "Skip confirmation prompt (required in non-interactive mode)"},
20+
},
21+
Action: func(c *cli.Context) error {
22+
apiClient, err := getClient(c)
23+
if err != nil {
24+
return err
25+
}
26+
27+
clientID, err := resolveOAuthClientID(c, apiClient)
28+
if err != nil {
29+
return err
30+
}
31+
32+
if !c.Bool("force") {
33+
if !terminal.IsInteractive() {
34+
return fmt.Errorf("use --force to confirm deletion in non-interactive mode\n\n Example:\n createos oauth-clients delete --client %s --force", clientID)
35+
}
36+
confirm, err := pterm.DefaultInteractiveConfirm.
37+
WithDefaultText(fmt.Sprintf("Permanently delete OAuth client %q?", clientID)).
38+
WithDefaultValue(false).
39+
Show()
40+
if err != nil {
41+
return fmt.Errorf("could not read confirmation: %w", err)
42+
}
43+
if !confirm {
44+
fmt.Println("Cancelled. Your OAuth client was not deleted.")
45+
return nil
46+
}
47+
}
48+
49+
if err := apiClient.DeleteOAuthClient(clientID); err != nil {
50+
return err
51+
}
52+
53+
pterm.Success.Println("OAuth client deleted.")
54+
return nil
55+
},
56+
}
57+
}

cmd/oauth/oauth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func NewOAuthCommand() *cli.Command {
1010
Subcommands: []*cli.Command{
1111
newListCommand(),
1212
newCreateCommand(),
13+
newDeleteCommand(),
1314
newInstructionsCommand(),
1415
},
1516
}

0 commit comments

Comments
 (0)