update

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LabelKeyKey   = "key"
	LabelValueKey = "value"
)
View Source
const (
	NameKey         = "name"
	NameShorthand   = "n"
	LabelsKey       = "labels"
	LabelsShorthand = "l"
)
View Source
const (
	LabelToDeleteKey = "key"
)

Variables

View Source
var AddLabelCmd = &cobra.Command{
	Use:          "add-label <environment-id>",
	Short:        "Add a label to an environment",
	Args:         cobra.ExactArgs(1),
	SilenceUsage: true,
	RunE: func(_ *cobra.Command, args []string) error {
		ctxTimeout, cancel := context.WithTimeout(context.Background(), config.DefaultTimeout)
		defer cancel()

		c, err := cloudclient.NewClient(ctxTimeout)
		if err != nil {
			return err
		}

		id := args[0]
		r, err := c.AddEnvironmentLabelMutationWithResponse(ctxTimeout,
			id,
			cloudapi.AddEnvironmentLabelMutationJSONRequestBody{
				Label: cloudclient.LabelToLabelInput(viper.GetString(LabelKeyKey), viper.GetString(LabelValueKey)),
			},
		)
		if err != nil {
			return err
		}

		prints.PrintCliStderr("Environment updated")
		output.FormatEnvs([]cloudapi.Environment{lo.FromPtr(r.JSON200)})
		return nil
	},
}
View Source
var RemoveAllLabelsCmd = &cobra.Command{
	Use:          "remove-all-labels <environment-id>",
	Short:        "Remove all labels from an environment",
	Args:         cobra.ExactArgs(1),
	SilenceUsage: true,
	RunE: func(_ *cobra.Command, args []string) error {
		ctxTimeout, cancel := context.WithTimeout(context.Background(), config.DefaultTimeout)
		defer cancel()

		c, err := cloudclient.NewClient(ctxTimeout)
		if err != nil {
			return err
		}

		id := args[0]

		emptyLabels := make([]cloudapi.LabelInput, 0)
		params := cloudapi.UpdateEnvironmentMutationJSONRequestBody{
			Labels: lo.ToPtr(emptyLabels),
		}

		response, err := c.UpdateEnvironmentMutationWithResponse(ctxTimeout, id, params)
		if err != nil {
			return err
		}

		prints.PrintCliStderr("Environment updated")
		output.FormatEnvs([]cloudapi.Environment{lo.FromPtr(response.JSON200)})
		return nil
	},
}
View Source
var RemoveLabelCmd = &cobra.Command{
	Use:          "remove-label <environment-id>",
	Short:        "Remove a label from an environment",
	Args:         cobra.ExactArgs(1),
	SilenceUsage: true,
	RunE: func(_ *cobra.Command, args []string) error {
		ctxTimeout, cancel := context.WithTimeout(context.Background(), config.DefaultTimeout)
		defer cancel()

		c, err := cloudclient.NewClient(ctxTimeout)
		if err != nil {
			return err
		}

		id := args[0]
		r, err := c.DeleteEnvironmentLabelMutationWithResponse(ctxTimeout,
			id,
			viper.GetString(LabelKeyKey),
		)
		if err != nil {
			return err
		}

		prints.PrintCliStderr("Environment updated")
		output.FormatEnvs([]cloudapi.Environment{lo.FromPtr(r.JSON200)})
		return nil
	},
}
View Source
var UpdateEnvCmd = &cobra.Command{
	Use:          "update <environment-id>",
	Short:        "Update an environment",
	Args:         cobra.ExactArgs(1),
	SilenceUsage: true,
	RunE: func(_ *cobra.Command, args []string) error {
		ctxTimeout, cancel := context.WithTimeout(context.Background(), config.DefaultTimeout)
		defer cancel()

		c, err := cloudclient.NewClient(ctxTimeout)
		if err != nil {
			return err
		}

		id := args[0]

		params := cloudapi.UpdateEnvironmentMutationJSONRequestBody{}
		if viper.IsSet(NameKey) {
			name := viper.GetString(NameKey)
			params.Name = lo.ToPtr(name)
		}

		if viper.IsSet(LabelsKey) {
			labels := cloudclient.LabelsToLabelInput(viper.GetStringMapString(LabelsKey))
			params.Labels = lo.ToPtr(labels)
		}

		response, err := c.UpdateEnvironmentMutationWithResponse(ctxTimeout, id, params)
		if err != nil {
			return err
		}

		prints.PrintCliStderr("Environment updated")
		output.FormatEnvs([]cloudapi.Environment{lo.FromPtr(response.JSON200)})
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL