From fe2c61b8a4520e6149e25f3b3ac055ca14a069dc Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Thu, 7 Aug 2025 06:38:09 +0200 Subject: [PATCH] feat(digitalocean/doctl): extend command --- arbitrary/task/command.go | 4 +- digitalocean/doctl/command.go | 73 ++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/arbitrary/task/command.go b/arbitrary/task/command.go index 3f108d5..203bb16 100644 --- a/arbitrary/task/command.go +++ b/arbitrary/task/command.go @@ -111,7 +111,7 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error { if err := c.executeTask(ctx, r.Args().At(0)); err != nil { return err } - c.l.Info("๐Ÿ––done") + c.l.Success("๐Ÿ”ง | done") return nil } @@ -159,7 +159,7 @@ func (c *Command) executeTask(ctx context.Context, taskID string) error { sh.Stdout = os.Stdout sh.Stderr = os.Stderr sh.Env = os.Environ() - c.l.Infof("[%d|%d] %s: %s", i+1, len(task.Cmds), taskID, cmd) + c.l.Infof("๐Ÿ”ง | [%d|%d] %s: %s", i+1, len(task.Cmds), taskID, cmd) if err := sh.Run(); err != nil { return err } diff --git a/digitalocean/doctl/command.go b/digitalocean/doctl/command.go index 7dd7b47..555b019 100644 --- a/digitalocean/doctl/command.go +++ b/digitalocean/doctl/command.go @@ -70,26 +70,61 @@ func NewCommand(l log.Logger, cache cache.Cache, doctl *Doctl, kubectl *kubectl. Description: "Manage digital ocean resources", Nodes: tree.Nodes{ { - Name: "auth", - Execute: inst.auth, - }, - { - Name: "kubeconfig", - Description: "Retrieve credentials to access remote cluster.", - Args: tree.Args{ + Name: "auth", + Description: "Manage authentication", + Nodes: tree.Nodes{ { - Name: "cluster", - Description: "Name of the cluster.", - Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest { - return suggests.List(inst.doctl.cfg.ClusterNames()) - }, + Name: "init", + Description: "Initialize doctl to use a specific account", + Execute: inst.exec, }, }, - Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error { - fs.Internal().String("profile", "", "Store credentials in given profile.") - return fs.Internal().SetValues("profile", "digitalocean") + Execute: inst.exec, + }, + { + Name: "registry", + Description: "Manage container registries", + Nodes: tree.Nodes{ + { + Name: "login", + Description: "Log in Docker to a container registry", + Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error { + fs.Default().Bool("never-expire", false, "Never expire the credentials") + return nil + }, + Execute: inst.exec, + }, + { + Name: "logout", + Description: "Log out Docker from a container registry", + Execute: inst.exec, + }, + }, + Execute: inst.exec, + }, + { + Name: "kubernetes", + Description: "Manage Kubernetes clusters", + Nodes: tree.Nodes{ + { + Name: "kubeconfig", + Description: "Retrieve credentials to access remote cluster.", + Args: tree.Args{ + { + Name: "cluster", + Description: "Name of the cluster.", + Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest { + return suggests.List(inst.doctl.cfg.ClusterNames()) + }, + }, + }, + Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error { + fs.Internal().String("profile", "", "Store credentials in given profile.") + return fs.Internal().SetValues("profile", "digitalocean") + }, + Execute: inst.kubeconfig, + }, }, - Execute: inst.kubeconfig, }, }, }) @@ -152,10 +187,10 @@ func (c *Command) kubeconfig(ctx context.Context, r *readline.Readline) error { Run() } -func (c *Command) auth(ctx context.Context, r *readline.Readline) error { - return shell.New(ctx, c.l, "doctl", "auth", "init"). +func (c *Command) exec(ctx context.Context, r *readline.Readline) error { + return shell.New(ctx, c.l, "doctl"). + Args(r.Args()...). Args(r.Flags()...). Args(r.AdditionalArgs()...). - Args(r.AdditionalFlags()...). Run() }