github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/uniter/runner/jujuc/k8s-spec-get.go (about)

     1  // Copyright 2019 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuc
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/cmd/v3"
    10  	"github.com/juju/errors"
    11  
    12  	jujucmd "github.com/juju/juju/cmd"
    13  )
    14  
    15  // K8sSpecGetCommand implements the k8s-spec-get command.
    16  type K8sSpecGetCommand struct {
    17  	cmd.CommandBase
    18  	name string
    19  	ctx  Context
    20  }
    21  
    22  // NewK8sSpecGetCommand makes a k8s-spec-get command.
    23  func NewK8sSpecGetCommand(ctx Context, name string) (cmd.Command, error) {
    24  	return &K8sSpecGetCommand{ctx: ctx, name: name}, nil
    25  }
    26  
    27  func (c *K8sSpecGetCommand) Info() *cmd.Info {
    28  	doc := `
    29  Gets configuration data used to set up k8s resources.
    30  `
    31  	purpose := "get k8s spec information"
    32  	if c.name == "pod-spec-get" {
    33  		purpose += " (deprecated)"
    34  	}
    35  	return jujucmd.Info(&cmd.Info{
    36  		Name:    c.name,
    37  		Purpose: purpose,
    38  		Doc:     doc,
    39  	})
    40  }
    41  
    42  func (c *K8sSpecGetCommand) Run(ctx *cmd.Context) error {
    43  	spec, err := c.ctx.GetPodSpec()
    44  	if err != nil {
    45  		return errors.Trace(err)
    46  	}
    47  	fmt.Fprint(ctx.Stdout, spec)
    48  	return nil
    49  }