github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/gc/gc.go (about)

     1  package gc
     2  
     3  import (
     4  	"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
     5  	"github.com/spf13/cobra"
     6  
     7  	"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
     8  	"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
     9  )
    10  
    11  // GCOptions is the start of the data required to perform the operation.  As new fields are added, add them here instead of
    12  // referencing the cmd.Flags()
    13  type GCOptions struct {
    14  	*opts.CommonOptions
    15  
    16  	Output string
    17  }
    18  
    19  const (
    20  	valid_gc_resources = `Valid resource types include:
    21  
    22      * activities
    23  	* helm
    24  	* previews
    25  	* releases
    26      `
    27  )
    28  
    29  var (
    30  	gc_long = templates.LongDesc(`
    31  		Garbage collect resources
    32  
    33  		` + valid_gc_resources + `
    34  
    35  `)
    36  
    37  	gc_example = templates.Examples(`
    38  		jx gc activities
    39  		jx gc gke
    40  		jx gc helm
    41  		jx gc previews
    42  		jx gc releases
    43  
    44  	`)
    45  )
    46  
    47  // NewCmdGC creates a command object for the generic "gc" action, which
    48  // retrieves one or more resources from a server.
    49  func NewCmdGC(commonOpts *opts.CommonOptions) *cobra.Command {
    50  	options := &GCOptions{
    51  		CommonOptions: commonOpts,
    52  	}
    53  
    54  	cmd := &cobra.Command{
    55  		Use:     "gc TYPE [flags]",
    56  		Short:   "Garbage collects Jenkins X resources",
    57  		Long:    gc_long,
    58  		Example: gc_example,
    59  		Run: func(cmd *cobra.Command, args []string) {
    60  			options.Cmd = cmd
    61  			options.Args = args
    62  			err := options.Run()
    63  			helper.CheckErr(err)
    64  		},
    65  	}
    66  
    67  	cmd.AddCommand(NewCmdGCActivities(commonOpts))
    68  	cmd.AddCommand(NewCmdGCPreviews(commonOpts))
    69  	cmd.AddCommand(NewCmdGCGKE(commonOpts))
    70  	cmd.AddCommand(NewCmdGCHelm(commonOpts))
    71  	cmd.AddCommand(NewCmdGCPods(commonOpts))
    72  	cmd.AddCommand(NewCmdGCReleases(commonOpts))
    73  
    74  	return cmd
    75  }
    76  
    77  // Run implements this command
    78  func (o *GCOptions) Run() error {
    79  	return o.Cmd.Help()
    80  }