github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/cmd/state/internal/cmdtree/platforms.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/platforms"
     8  )
     9  
    10  func newPlatformsCommand(prime *primer.Values) *captain.Command {
    11  	runner := platforms.NewList(prime)
    12  
    13  	return captain.NewCommand(
    14  		"platforms",
    15  		locale.Tl("platforms_title", "Listing Platforms"),
    16  		locale.T("platforms_cmd_description"),
    17  		prime,
    18  		[]*captain.Flag{},
    19  		[]*captain.Argument{},
    20  		func(_ *captain.Command, _ []string) error {
    21  			return runner.Run()
    22  		},
    23  	).SetGroup(PlatformGroup).SetSupportsStructuredOutput().SetUnstable(true)
    24  }
    25  
    26  func newPlatformsSearchCommand(prime *primer.Values) *captain.Command {
    27  	runner := platforms.NewSearch(prime)
    28  
    29  	return captain.NewCommand(
    30  		"search",
    31  		locale.Tl("platforms_search_title", "Searching Platforms"),
    32  		locale.T("platforms_search_cmd_description"),
    33  		prime,
    34  		[]*captain.Flag{},
    35  		[]*captain.Argument{},
    36  		func(_ *captain.Command, _ []string) error {
    37  			return runner.Run()
    38  		},
    39  	).SetSupportsStructuredOutput()
    40  }
    41  
    42  func newPlatformsAddCommand(prime *primer.Values) *captain.Command {
    43  	runner := platforms.NewAdd(prime)
    44  
    45  	params := platforms.AddRunParams{}
    46  
    47  	return captain.NewCommand(
    48  		"add",
    49  		locale.Tl("platforms_add_title", "Adding Platform"),
    50  		locale.T("platforms_add_cmd_description"),
    51  		prime,
    52  		[]*captain.Flag{
    53  			{
    54  				Name:        "bit-width",
    55  				Description: locale.T("flag_platforms_shared_bitwidth_description"),
    56  				Value:       &params.BitWidth,
    57  			},
    58  		},
    59  		[]*captain.Argument{
    60  			{
    61  				Name:        locale.T("arg_platforms_shared_name"),
    62  				Description: locale.T("arg_platforms_shared_name_description"),
    63  				Value:       &params.Platform,
    64  				Required:    true,
    65  			},
    66  		},
    67  		func(_ *captain.Command, _ []string) error {
    68  			return runner.Run(params)
    69  		},
    70  	).SetSupportsStructuredOutput()
    71  }
    72  
    73  func newPlatformsRemoveCommand(prime *primer.Values) *captain.Command {
    74  	runner := platforms.NewRemove(prime)
    75  
    76  	params := platforms.RemoveRunParams{}
    77  
    78  	return captain.NewCommand(
    79  		"remove",
    80  		locale.Tl("platforms_remove_title", "Removing Platform"),
    81  		locale.T("platforms_remove_cmd_description"),
    82  		prime,
    83  		[]*captain.Flag{
    84  			{
    85  				Name:        "bit-width",
    86  				Description: locale.T("flag_platforms_shared_bitwidth_description"),
    87  				Value:       &params.BitWidth,
    88  			},
    89  		},
    90  		[]*captain.Argument{
    91  			{
    92  				Name:        locale.T("arg_platforms_shared_name"),
    93  				Description: locale.T("arg_platforms_shared_name_description"),
    94  				Value:       &params.Platform,
    95  				Required:    true,
    96  			},
    97  		},
    98  		func(_ *captain.Command, _ []string) error {
    99  			return runner.Run(params)
   100  		},
   101  	).SetSupportsStructuredOutput()
   102  }