github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/cmd/state/internal/cmdtree/clean.go (about)

     1  package cmdtree
     2  
     3  import (
     4  	"github.com/ActiveState/cli/internal/captain"
     5  	"github.com/ActiveState/cli/internal/locale"
     6  	"github.com/ActiveState/cli/internal/primer"
     7  	"github.com/ActiveState/cli/internal/runners/clean"
     8  )
     9  
    10  func newCleanCommand(prime *primer.Values) *captain.Command {
    11  	return captain.NewCommand(
    12  		"clean",
    13  		locale.Tl("clean_title", "Cleaning Resources"),
    14  		locale.T("clean_description"),
    15  		prime,
    16  		[]*captain.Flag{},
    17  		[]*captain.Argument{},
    18  		func(ccmd *captain.Command, _ []string) error {
    19  			prime.Output().Print(ccmd.Help())
    20  			return nil
    21  		},
    22  	).SetGroup(UtilsGroup).SetSupportsStructuredOutput()
    23  }
    24  
    25  func newCleanUninstallCommand(prime *primer.Values, globals *globalOptions) *captain.Command {
    26  	params := clean.UninstallParams{}
    27  	return captain.NewCommand(
    28  		"uninstall",
    29  		locale.Tl("clean_uninstall_title", "Uninstalling"),
    30  		locale.T("uninstall_description"),
    31  		prime,
    32  		[]*captain.Flag{
    33  			{
    34  				Name:        "all",
    35  				Shorthand:   "a",
    36  				Description: locale.Tl("flag_state_clean_uninstall_all", "Also delete all associated config and cache files"),
    37  				Value:       &params.All,
    38  			},
    39  			{
    40  				Name:        "force",
    41  				Shorthand:   "f",
    42  				Description: locale.T("flag_state_clean_uninstall_force_description"),
    43  				Value:       &params.Force,
    44  			},
    45  			{
    46  				// This option is only used by the Windows uninstall shortcut to ask the user if they wish
    47  				// to delete everything or keep cache and config. The user is also asked to press Enter
    48  				// after the uninstall process is scheduled so they may note the printed log file path.
    49  				Name:        "prompt",
    50  				Description: "Asks the user if everything should be deleted or to keep cache and config",
    51  				Hidden:      true, // this is not a user-facing flag
    52  				Value:       &params.Prompt,
    53  			},
    54  		},
    55  		[]*captain.Argument{},
    56  		func(ccmd *captain.Command, _ []string) error {
    57  			runner, err := clean.NewUninstall(prime)
    58  			if err != nil {
    59  				return err
    60  			}
    61  
    62  			params.NonInteractive = globals.NonInteractive // distinct from --force
    63  			return runner.Run(&params)
    64  		},
    65  	)
    66  }
    67  
    68  func newCleanCacheCommand(prime *primer.Values, globals *globalOptions) *captain.Command {
    69  	runner := clean.NewCache(prime)
    70  	params := clean.CacheParams{}
    71  	return captain.NewCommand(
    72  		"cache",
    73  		locale.Tl("clean_cache_title", "Cleaning Cached Runtimes"),
    74  		locale.T("cache_description"),
    75  		prime,
    76  		[]*captain.Flag{},
    77  		[]*captain.Argument{
    78  			{
    79  				Name:        "org/project",
    80  				Description: locale.T("arg_state_clean_cache_project_description"),
    81  				Required:    false,
    82  				Value:       &params.Project,
    83  			},
    84  		},
    85  		func(ccmd *captain.Command, _ []string) error {
    86  			params.Force = globals.NonInteractive
    87  			return runner.Run(&params)
    88  		},
    89  	)
    90  }
    91  
    92  func newCleanConfigCommand(prime *primer.Values) *captain.Command {
    93  	runner := clean.NewConfig(prime)
    94  	params := clean.ConfigParams{}
    95  	return captain.NewCommand(
    96  		"config",
    97  		locale.Tl("clean_config_title", "Cleaning Configuration"),
    98  		locale.T("clean_config_description"),
    99  		prime,
   100  		[]*captain.Flag{
   101  			{
   102  				Name:        "force",
   103  				Shorthand:   "f",
   104  				Description: locale.T("flag_state_clean_config_force_description"),
   105  				Value:       &params.Force,
   106  			},
   107  		},
   108  		[]*captain.Argument{},
   109  		func(ccmd *captain.Command, _ []string) error {
   110  			return runner.Run(&params)
   111  		},
   112  	)
   113  }