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

     1  package cmdtree
     2  
     3  import (
     4  	"runtime"
     5  
     6  	"github.com/ActiveState/cli/internal/captain"
     7  	"github.com/ActiveState/cli/internal/locale"
     8  	"github.com/ActiveState/cli/internal/primer"
     9  	"github.com/ActiveState/cli/internal/runners/deploy"
    10  	"github.com/ActiveState/cli/internal/runners/deploy/uninstall"
    11  )
    12  
    13  func newDeployCommand(prime *primer.Values) *captain.Command {
    14  	runner := deploy.NewDeploy(deploy.UnsetStep, prime)
    15  
    16  	params := &deploy.Params{}
    17  
    18  	flags := []*captain.Flag{
    19  		{
    20  			Name:        "path",
    21  			Description: locale.T("flag_state_deploy_path_description"),
    22  			Value:       &params.Path,
    23  		},
    24  		{
    25  			Name:        "force",
    26  			Description: locale.T("flag_state_deploy_force_description"),
    27  			Value:       &params.Force,
    28  		},
    29  	}
    30  	if runtime.GOOS == "windows" {
    31  		flags = append(flags, &captain.Flag{
    32  			Name:        "user",
    33  			Description: locale.T("flag_state_deploy_user_path_description"),
    34  			Value:       &params.UserScope,
    35  		})
    36  	}
    37  
    38  	cmd := captain.NewCommand(
    39  		"deploy",
    40  		locale.Tl("deploy_title", "Deploying Runtime"),
    41  		locale.T("deploy_cmd_description"),
    42  		prime,
    43  		flags,
    44  		[]*captain.Argument{
    45  			{
    46  				Name:        locale.T("arg_state_deploy_namespace"),
    47  				Description: locale.T("arg_state_deploy_namespace_description"),
    48  				Value:       &params.Namespace,
    49  				Required:    true,
    50  			},
    51  		},
    52  		func(cmd *captain.Command, args []string) error {
    53  			return runner.Run(params)
    54  		})
    55  	cmd.SetGroup(EnvironmentSetupGroup)
    56  	cmd.SetHidden(true)
    57  	return cmd
    58  }
    59  
    60  func newDeployInstallCommand(prime *primer.Values) *captain.Command {
    61  	runner := deploy.NewDeploy(deploy.InstallStep, prime)
    62  
    63  	params := &deploy.Params{}
    64  
    65  	return captain.NewCommand(
    66  		"install",
    67  		locale.Tl("deploy_install_title", "Installing Runtime (Unconfigured)"),
    68  		locale.T("deploy_install_cmd_description"),
    69  		prime,
    70  		[]*captain.Flag{
    71  			{
    72  				Name:        "path",
    73  				Description: locale.T("flag_state_deploy_path_description"),
    74  				Value:       &params.Path,
    75  			},
    76  		},
    77  		[]*captain.Argument{
    78  			{
    79  				Name:        locale.T("arg_state_deploy_namespace"),
    80  				Description: locale.T("arg_state_deploy_namespace_description"),
    81  				Value:       &params.Namespace,
    82  				Required:    true,
    83  			},
    84  		},
    85  		func(cmd *captain.Command, args []string) error {
    86  			return runner.Run(params)
    87  		})
    88  }
    89  
    90  func newDeployConfigureCommand(prime *primer.Values) *captain.Command {
    91  	runner := deploy.NewDeploy(deploy.ConfigureStep, prime)
    92  
    93  	params := &deploy.Params{}
    94  
    95  	flags := []*captain.Flag{
    96  		{
    97  			Name:        "path",
    98  			Description: locale.T("flag_state_deploy_path_description"),
    99  			Value:       &params.Path,
   100  		},
   101  	}
   102  	if runtime.GOOS == "windows" {
   103  		flags = append(flags, &captain.Flag{
   104  			Name:        "user",
   105  			Description: locale.T("flag_state_deploy_user_path_description"),
   106  			Value:       &params.UserScope,
   107  		})
   108  	}
   109  
   110  	return captain.NewCommand(
   111  		"configure",
   112  		locale.Tl("deploy_configure_title", "Configuring Runtime For Your Shell"),
   113  		locale.T("deploy_configure_cmd_description"),
   114  		prime,
   115  		flags,
   116  		[]*captain.Argument{
   117  			{
   118  				Name:        locale.T("arg_state_deploy_namespace"),
   119  				Description: locale.T("arg_state_deploy_namespace_description"),
   120  				Value:       &params.Namespace,
   121  				Required:    true,
   122  			},
   123  		},
   124  		func(cmd *captain.Command, args []string) error {
   125  			return runner.Run(params)
   126  		})
   127  }
   128  
   129  func newDeploySymlinkCommand(prime *primer.Values) *captain.Command {
   130  	runner := deploy.NewDeploy(deploy.SymlinkStep, prime)
   131  
   132  	params := &deploy.Params{}
   133  
   134  	return captain.NewCommand(
   135  		"symlink",
   136  		locale.Tl("deploy_symlink_title", "Symlinking Executables"),
   137  		locale.T("deploy_symlink_cmd_description"),
   138  		prime,
   139  		[]*captain.Flag{
   140  			{
   141  				Name:        "path",
   142  				Description: locale.T("flag_state_deploy_path_description"),
   143  				Value:       &params.Path,
   144  			},
   145  			{
   146  				Name:        "force",
   147  				Description: locale.T("flag_state_deploy_force_description"),
   148  				Value:       &params.Force,
   149  			},
   150  		},
   151  		[]*captain.Argument{
   152  			{
   153  				Name:        locale.T("arg_state_deploy_namespace"),
   154  				Description: locale.T("arg_state_deploy_namespace_description"),
   155  				Value:       &params.Namespace,
   156  				Required:    true,
   157  			},
   158  		},
   159  		func(cmd *captain.Command, args []string) error {
   160  			return runner.Run(params)
   161  		})
   162  }
   163  
   164  func newDeployReportCommand(prime *primer.Values) *captain.Command {
   165  	runner := deploy.NewDeploy(deploy.ReportStep, prime)
   166  
   167  	params := &deploy.Params{}
   168  
   169  	return captain.NewCommand(
   170  		"report",
   171  		locale.Tl("deploy_report_title", "Reporting Deployment Information"),
   172  		locale.T("deploy_report_cmd_description"),
   173  		prime,
   174  		[]*captain.Flag{
   175  			{
   176  				Name:        "path",
   177  				Description: locale.T("flag_state_deploy_path_description"),
   178  				Value:       &params.Path,
   179  			},
   180  		},
   181  		[]*captain.Argument{
   182  			{
   183  				Name:        locale.T("arg_state_deploy_namespace"),
   184  				Description: locale.T("arg_state_deploy_namespace_description"),
   185  				Value:       &params.Namespace,
   186  				Required:    true,
   187  			},
   188  		},
   189  		func(cmd *captain.Command, args []string) error {
   190  			return runner.Run(params)
   191  		})
   192  }
   193  
   194  func newDeployUninstallCommand(prime *primer.Values) *captain.Command {
   195  	runner := uninstall.NewDeployUninstall(prime)
   196  
   197  	params := &uninstall.Params{}
   198  
   199  	flags := []*captain.Flag{
   200  		{
   201  			Name:        "path",
   202  			Description: locale.Tl("flag_state_deploy_uninstall_path_description", "The path of the deployed runtime to uninstall if not the current directory"),
   203  			Value:       &params.Path,
   204  		},
   205  	}
   206  	if runtime.GOOS == "windows" {
   207  		flags = append(flags, &captain.Flag{
   208  			Name:        "user",
   209  			Description: locale.T("flag_state_deploy_user_path_description"),
   210  			Value:       &params.UserScope,
   211  		})
   212  	}
   213  
   214  	return captain.NewCommand(
   215  		"uninstall",
   216  		locale.Tl("deploy_uninstall_title", "Uninstall Deployed Runtime"),
   217  		locale.Tl("deploy_uninstall_cmd_description", "Removes a runtime that had previously been deployed"),
   218  		prime,
   219  		flags,
   220  		[]*captain.Argument{},
   221  		func(cmd *captain.Command, args []string) error {
   222  			return runner.Run(params)
   223  		})
   224  }