github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/cmd/state/internal/cmdtree/checkout.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/checkout"
     8  	"github.com/ActiveState/cli/pkg/project"
     9  )
    10  
    11  func newCheckoutCommand(prime *primer.Values) *captain.Command {
    12  	params := &checkout.Params{
    13  		Namespace: &project.Namespaced{AllowOmitOwner: true},
    14  	}
    15  
    16  	cmd := captain.NewCommand(
    17  		"checkout",
    18  		"",
    19  		locale.Tl("checkout_description", "Checkout the given project and setup its runtime"),
    20  		prime,
    21  		[]*captain.Flag{
    22  			{
    23  				Name:        "branch",
    24  				Description: locale.Tl("flag_state_checkout_branch_description", "Defines the branch to checkout"),
    25  				Value:       &params.Branch,
    26  			},
    27  			{
    28  				Name:        "runtime-path",
    29  				Description: locale.Tl("flag_state_checkout_runtime-path_description", "Path to store the runtime files"),
    30  				Value:       &params.RuntimePath,
    31  			},
    32  			{
    33  				Name:        "no-clone",
    34  				Description: locale.Tl("flag_state_checkout_no_clone_description", "Do not clone the github repository associated with this project (if any)"),
    35  				Value:       &params.NoClone,
    36  			},
    37  			{
    38  				Name:        "force",
    39  				Shorthand:   "f",
    40  				Description: locale.Tl("flag_state_checkout_force", "Leave a failed project checkout on disk; do not delete it"),
    41  				Value:       &params.Force,
    42  			},
    43  		},
    44  		[]*captain.Argument{
    45  			{
    46  				Name:        locale.Tl("arg_state_checkout_namespace", "org/project"),
    47  				Description: locale.Tl("arg_state_checkout_namespace_description", "The namespace of the project that you wish to checkout"),
    48  				Required:    true,
    49  				Value:       params.Namespace,
    50  			},
    51  			{
    52  				Name:        locale.Tl("arg_state_checkout_path", "path"),
    53  				Description: locale.Tl("flag_state_checkout_path_description", "Where to checkout the project. If not given, the project is checked out to a sub-folder in the current working directory"),
    54  				Value:       &params.PreferredPath,
    55  			},
    56  		},
    57  		func(_ *captain.Command, _ []string) error {
    58  			return checkout.NewCheckout(prime).Run(params)
    59  		},
    60  	)
    61  	cmd.SetGroup(EnvironmentSetupGroup)
    62  	cmd.SetSupportsStructuredOutput()
    63  	return cmd
    64  }