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

     1  package cmdtree
     2  
     3  import (
     4  	"github.com/ActiveState/cli/internal/primer"
     5  	"github.com/ActiveState/cli/internal/runners/update"
     6  
     7  	"github.com/ActiveState/cli/internal/captain"
     8  	"github.com/ActiveState/cli/internal/locale"
     9  )
    10  
    11  func newUpdateCommand(prime *primer.Values) *captain.Command {
    12  	runner := update.New(prime)
    13  	params := update.Params{}
    14  
    15  	cmd := captain.NewCommand(
    16  		"update",
    17  		locale.Tl("update_title", "Updating The State Tool"),
    18  		locale.Tl("update_description", "Updates the State Tool to the latest available version"),
    19  		prime,
    20  		[]*captain.Flag{
    21  			{
    22  				Name:        "set-channel",
    23  				Description: locale.Tl("update_channel", "Switches to the given update channel, eg. 'release'."),
    24  				Value:       &params.Channel,
    25  			},
    26  		},
    27  		[]*captain.Argument{},
    28  		func(cmd *captain.Command, args []string) error {
    29  			return runner.Run(&params)
    30  		},
    31  	)
    32  	cmd.SetGroup(UtilsGroup)
    33  	cmd.SetSkipChecks(true)
    34  	return cmd
    35  }
    36  
    37  func newUpdateLockCommand(prime *primer.Values, globals *globalOptions) *captain.Command {
    38  	runner := update.NewLock(prime)
    39  	params := update.LockParams{}
    40  
    41  	cmd := captain.NewCommand(
    42  		"lock",
    43  		locale.Tl("lock_title", "Lock the State Tool version"),
    44  		locale.Tl("lock_description", "Lock the State Tool at the current version, this disables automatic updates."),
    45  		prime,
    46  		[]*captain.Flag{
    47  			{
    48  				Name:        "set-channel",
    49  				Description: locale.Tl("update_channel", "Switches to the given update channel, eg. 'release'."),
    50  				Value:       &params.Channel,
    51  			},
    52  		},
    53  		[]*captain.Argument{},
    54  		func(cmd *captain.Command, args []string) error {
    55  			params.NonInteractive = globals.NonInteractive
    56  			return runner.Run(&params)
    57  		},
    58  	)
    59  	cmd.SetSkipChecks(true)
    60  	cmd.SetSupportsStructuredOutput()
    61  	return cmd
    62  }
    63  
    64  func newUpdateUnlockCommand(prime *primer.Values, globals *globalOptions) *captain.Command {
    65  	runner := update.NewUnlock(prime)
    66  	params := update.UnlockParams{}
    67  
    68  	cmd := captain.NewCommand(
    69  		"unlock",
    70  		locale.Tl("unlock_title", "Unlock the State Tool version"),
    71  		locale.Tl("unlock_description", "Unlock the State Tool version for the current project."),
    72  		prime,
    73  		[]*captain.Flag{},
    74  		[]*captain.Argument{},
    75  		func(cmd *captain.Command, args []string) error {
    76  			params.NonInteractive = globals.NonInteractive
    77  			return runner.Run(&params)
    78  		},
    79  	)
    80  	cmd.SetSkipChecks(true)
    81  	return cmd
    82  }