github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/prompts/internal/tags.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/pterm/pterm"
     5  	"github.com/taubyte/tau-cli/flags"
     6  	"github.com/taubyte/tau-cli/prompts"
     7  	"github.com/urfave/cli/v2"
     8  )
     9  
    10  var TagsCommand = &cli.Command{
    11  	Name: "tags",
    12  	Flags: []cli.Flag{
    13  		flags.Tags,
    14  	},
    15  	Action: func(ctx *cli.Context) error {
    16  		tagsPrompt(ctx, false)
    17  
    18  		return nil
    19  	},
    20  }
    21  
    22  var TagsRequiredCommand = &cli.Command{
    23  	Name: "tags-required",
    24  	Flags: []cli.Flag{
    25  		flags.Tags,
    26  	},
    27  	Action: func(ctx *cli.Context) error {
    28  		tagsPrompt(ctx, true)
    29  
    30  		return nil
    31  	},
    32  }
    33  
    34  func tagsPrompt(ctx *cli.Context, required bool) {
    35  	var tags []string
    36  	if required {
    37  		// New
    38  		tags = prompts.RequiredTags(ctx)
    39  
    40  		// Edit
    41  		tags = prompts.RequiredTags(&cli.Context{}, tags)
    42  	} else {
    43  		// New
    44  		tags = prompts.GetOrAskForTags(ctx)
    45  
    46  		// Edit
    47  		tags = prompts.GetOrAskForTags(&cli.Context{}, tags)
    48  	}
    49  
    50  	pterm.Success.Printfln("Got tags: `%v`", tags)
    51  }