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

     1  package cmdtree
     2  
     3  import (
     4  	"strings"
     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/export"
    10  	"github.com/ActiveState/cli/internal/runners/export/config"
    11  	"github.com/ActiveState/cli/internal/runners/export/docs"
    12  	"github.com/ActiveState/cli/internal/runners/export/ghactions"
    13  )
    14  
    15  func newExportCommand(prime *primer.Values) *captain.Command {
    16  	runner := export.NewExport()
    17  
    18  	return captain.NewCommand(
    19  		"export",
    20  		locale.Tl("export_title", "Exporting Information"),
    21  		locale.T("export_cmd_description"),
    22  		prime,
    23  		[]*captain.Flag{},
    24  		[]*captain.Argument{},
    25  		func(ccmd *captain.Command, args []string) error {
    26  			return runner.Run(ccmd)
    27  		}).SetGroup(UtilsGroup).SetSupportsStructuredOutput()
    28  }
    29  
    30  func newJWTCommand(prime *primer.Values) *captain.Command {
    31  	jwt := export.NewJWT(prime)
    32  
    33  	params := export.JWTParams{}
    34  
    35  	return captain.NewCommand(
    36  		"jwt",
    37  		locale.Tl("export_jwt_title", "Exporting Credentials"),
    38  		locale.T("export_jwt_cmd_description"),
    39  		prime,
    40  		[]*captain.Flag{},
    41  		[]*captain.Argument{},
    42  		func(ccmd *captain.Command, args []string) error {
    43  			return jwt.Run(&params)
    44  		}).SetSupportsStructuredOutput()
    45  }
    46  
    47  func newPrivateKeyCommand(prime *primer.Values) *captain.Command {
    48  	privateKey := export.NewPrivateKey(prime)
    49  
    50  	params := export.PrivateKeyParams{}
    51  
    52  	return captain.NewCommand(
    53  		"private-key",
    54  		locale.Tl("export_privkey_title", "Exporting Private Key"),
    55  		locale.T("export_privkey_cmd_description"),
    56  		prime,
    57  		[]*captain.Flag{},
    58  		[]*captain.Argument{},
    59  		func(ccmd *captain.Command, args []string) error {
    60  			return privateKey.Run(&params)
    61  		}).SetSupportsStructuredOutput()
    62  }
    63  
    64  func newAPIKeyCommand(prime *primer.Values) *captain.Command {
    65  	apikey := export.NewAPIKey(prime)
    66  	params := export.APIKeyRunParams{}
    67  
    68  	return captain.NewCommand(
    69  		"new-api-key",
    70  		locale.Tl("export_new_api_key_title", "Exporting New API Key"),
    71  		locale.T("export_new_api_key_cmd_description"),
    72  		prime,
    73  		[]*captain.Flag{},
    74  		[]*captain.Argument{
    75  			{
    76  				Name:        locale.T("export_new_api_key_arg_name"),
    77  				Description: locale.T("export_new_api_key_arg_name_description"),
    78  				Value:       &params.Name,
    79  				Required:    true,
    80  			},
    81  		},
    82  		func(ccmd *captain.Command, args []string) error {
    83  			params.IsAuthed = prime.Auth().Authenticated
    84  			return apikey.Run(params)
    85  		}).SetSupportsStructuredOutput()
    86  }
    87  
    88  func newExportConfigCommand(prime *primer.Values) *captain.Command {
    89  	runner := config.New(prime)
    90  	params := config.ConfigParams{}
    91  
    92  	return captain.NewCommand(
    93  		"config",
    94  		locale.Tl("export_config_title", "Exporting Configuration Data"),
    95  		locale.T("export_config_cmd_description"),
    96  		prime,
    97  		[]*captain.Flag{
    98  			{
    99  				Name: "filter",
   100  				Description: locale.Tr(
   101  					"export_config_flag_filter_description",
   102  					strings.Join(config.SupportedFilters(), ", "),
   103  				),
   104  				Value: &params.Filter,
   105  			},
   106  		},
   107  		[]*captain.Argument{},
   108  		func(ccmd *captain.Command, _ []string) error {
   109  			return runner.Run(ccmd, &params)
   110  		}).SetSupportsStructuredOutput().SetUnstable(true)
   111  }
   112  
   113  func newExportGithubActionCommand(prime *primer.Values) *captain.Command {
   114  	runner := ghactions.New(prime)
   115  	params := ghactions.Params{}
   116  
   117  	return captain.NewCommand(
   118  		"github-actions",
   119  		locale.Tl("export_ghactions_title", "Exporting Github Action Workflow"),
   120  		locale.Tl("export_ghactions_description", "Create a github action workflow for your project"),
   121  		prime,
   122  		[]*captain.Flag{},
   123  		[]*captain.Argument{},
   124  		func(ccmd *captain.Command, _ []string) error {
   125  			return runner.Run(&params)
   126  		}).SetUnstable(true)
   127  }
   128  
   129  func newExportDocsCommand(prime *primer.Values) *captain.Command {
   130  	runner := docs.New(prime)
   131  	params := docs.Params{}
   132  
   133  	cmd := captain.NewCommand(
   134  		"_docs",
   135  		locale.Tl("export_docs_title", "Export state tool command reference in markdown format"),
   136  		locale.Tl("export_docs_description", ""),
   137  		prime,
   138  		[]*captain.Flag{},
   139  		[]*captain.Argument{},
   140  		func(ccmd *captain.Command, _ []string) error {
   141  			return runner.Run(&params, ccmd)
   142  		})
   143  
   144  	cmd.SetHidden(true)
   145  
   146  	return cmd
   147  }
   148  
   149  func newExportEnvCommand(prime *primer.Values) *captain.Command {
   150  	runner := export.NewEnv(prime)
   151  
   152  	cmd := captain.NewCommand(
   153  		"env",
   154  		locale.Tl("env_docs_title", "Exporting environment"),
   155  		locale.Tl("env_docs_description", "Export the environment variables associated with your runtime."),
   156  		prime,
   157  		[]*captain.Flag{},
   158  		[]*captain.Argument{},
   159  		func(ccmd *captain.Command, _ []string) error {
   160  			return runner.Run()
   161  		})
   162  
   163  	cmd.SetSupportsStructuredOutput()
   164  	cmd.SetUnstable(true)
   165  
   166  	return cmd
   167  }
   168  
   169  func newLogCommand(prime *primer.Values) *captain.Command {
   170  	runner := export.NewLog(prime)
   171  	params := &export.LogParams{}
   172  
   173  	cmd := captain.NewCommand(
   174  		"log",
   175  		locale.Tl("export_log_title", "Show Log File"),
   176  		locale.Tl("export_log_description", "Show the path to a State Tool log file"),
   177  		prime,
   178  		[]*captain.Flag{
   179  			{
   180  				Name:        "index",
   181  				Shorthand:   "i",
   182  				Description: locale.Tl("flag_export_log_index", "The 0-based index of the log file to show, starting with the newest"),
   183  				Value:       &params.Index,
   184  			},
   185  		},
   186  		[]*captain.Argument{
   187  			{
   188  				Name:        "prefix",
   189  				Description: locale.Tl("arg_export_log_prefix", "The prefix of the log file to show (e.g. state or state-svc). The default is 'state'"),
   190  				Required:    false,
   191  				Value:       &params.Prefix,
   192  			},
   193  		},
   194  		func(ccmd *captain.Command, _ []string) error {
   195  			return runner.Run(params)
   196  		})
   197  
   198  	cmd.SetSupportsStructuredOutput()
   199  	cmd.SetUnstable(true)
   200  
   201  	return cmd
   202  }