github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/function/new.go (about)

     1  package function
     2  
     3  import (
     4  	structureSpec "github.com/taubyte/go-specs/structure"
     5  	resources "github.com/taubyte/tau-cli/cli/commands/resources/common"
     6  	"github.com/taubyte/tau-cli/cli/common"
     7  	"github.com/taubyte/tau-cli/flags"
     8  	functionFlags "github.com/taubyte/tau-cli/flags/function"
     9  	functionI18n "github.com/taubyte/tau-cli/i18n/function"
    10  	functionLib "github.com/taubyte/tau-cli/lib/function"
    11  	functionPrompts "github.com/taubyte/tau-cli/prompts/function"
    12  	functionTable "github.com/taubyte/tau-cli/table/function"
    13  	"github.com/urfave/cli/v2"
    14  )
    15  
    16  func (link) New() common.Command {
    17  	var templateURL string
    18  	return (&resources.New[*structureSpec.Function]{
    19  		PromptsNew: func(ctx *cli.Context) (*structureSpec.Function, error) {
    20  			function, _templateURL, err := functionPrompts.New(ctx)
    21  			templateURL = _templateURL
    22  			return function, err
    23  		},
    24  		TableConfirm:      functionTable.Confirm,
    25  		PromptsCreateThis: functionPrompts.CreateThis,
    26  		LibNew: func(function *structureSpec.Function) error {
    27  			return functionLib.New(function, templateURL)
    28  		},
    29  		I18nCreated: functionI18n.Created,
    30  
    31  		UniqueFlags: flags.Combine(
    32  			flags.Timeout,
    33  			flags.Memory,
    34  			flags.MemoryUnit,
    35  			functionFlags.Type,
    36  			flags.Source,
    37  			flags.Call,
    38  			flags.Template,
    39  			flags.Language,
    40  			flags.UseCodeTemplate,
    41  			functionFlags.Http(),
    42  
    43  			// P2P and PubSub
    44  			flags.Local,
    45  			functionFlags.P2P(),
    46  			functionFlags.PubSub(),
    47  		),
    48  	}).Default()
    49  }