Merge pull request #219 from foomo/feature/doctl

feat(digitalocean/doctl): extend command
This commit is contained in:
Kevin Franklin Kim 2025-08-07 06:44:39 +02:00 committed by GitHub
commit 6ce823eb4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 21 deletions

View File

@ -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
}

View File

@ -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()
}