github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/deletecmd/delete_addon_gitea.go (about)

     1  package deletecmd
     2  
     3  import (
     4  	"github.com/olli-ai/jx/v2/pkg/cmd/helper"
     5  	"github.com/olli-ai/jx/v2/pkg/cmd/opts"
     6  	"github.com/olli-ai/jx/v2/pkg/cmd/templates"
     7  	"github.com/olli-ai/jx/v2/pkg/util"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  var (
    12  	delete_addon_gitea_long = templates.LongDesc(`
    13  		Deletes the Gitea addon
    14  `)
    15  
    16  	delete_addon_gitea_example = templates.Examples(`
    17  		# Deletes the Gitea addon
    18  		jx delete addon gitea
    19  	`)
    20  )
    21  
    22  // DeleteAddonGiteaOptions the options for the create spring command
    23  type DeleteAddonGiteaOptions struct {
    24  	DeleteAddonOptions
    25  
    26  	ReleaseName string
    27  }
    28  
    29  // NewCmdDeleteAddonGitea defines the command
    30  func NewCmdDeleteAddonGitea(commonOpts *opts.CommonOptions) *cobra.Command {
    31  	options := &DeleteAddonGiteaOptions{
    32  		DeleteAddonOptions: DeleteAddonOptions{
    33  			CommonOptions: commonOpts,
    34  		},
    35  	}
    36  
    37  	cmd := &cobra.Command{
    38  		Use:     "gitea",
    39  		Short:   "Deletes the Gitea addon",
    40  		Long:    delete_addon_gitea_long,
    41  		Example: delete_addon_gitea_example,
    42  		Run: func(cmd *cobra.Command, args []string) {
    43  			options.Cmd = cmd
    44  			options.Args = args
    45  			err := options.Run()
    46  			helper.CheckErr(err)
    47  		},
    48  	}
    49  	cmd.Flags().StringVarP(&options.ReleaseName, opts.OptionRelease, "r", "gitea", "The chart release name")
    50  	options.addFlags(cmd)
    51  	return cmd
    52  }
    53  
    54  // Run implements the command
    55  func (o *DeleteAddonGiteaOptions) Run() error {
    56  	if o.ReleaseName == "" {
    57  		return util.MissingOption(opts.OptionRelease)
    58  	}
    59  	err := o.DeleteChart(o.ReleaseName, o.Purge)
    60  	if err != nil {
    61  		return err
    62  	}
    63  	return o.deleteGitServer()
    64  }
    65  
    66  func (o *DeleteAddonGiteaOptions) deleteGitServer() error {
    67  	options := &DeleteGitServerOptions{
    68  		CommonOptions:       o.CommonOptions,
    69  		IgnoreMissingServer: true,
    70  	}
    71  	options.Args = []string{"gitea"}
    72  	return options.Run()
    73  }