mirror of https://github.com/knative/func.git
enable stack short-names (aliases)
This commit is contained in:
parent
fdd7430199
commit
9e1f81560b
|
@ -9,6 +9,14 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// NameMappings are short-name to repository full name mappings,
|
||||
// enabling shorthand `faas create go` rather than `faas create go-ce-functions`
|
||||
var stackShortNames = map[string]string{
|
||||
"go": "go-ce-functions",
|
||||
"js": "node-ce-functions",
|
||||
"java": "quarkus-ce-functions",
|
||||
}
|
||||
|
||||
// Initializer of functions using the appsody binary.
|
||||
type Initializer struct {
|
||||
// Verbose logging flag.
|
||||
|
@ -35,11 +43,24 @@ func (n *Initializer) Initialize(name, language, path string) error {
|
|||
// any dots with dashes.
|
||||
name = strings.ReplaceAll(name, ".", "-")
|
||||
|
||||
// Dereference stack short name
|
||||
stackName, ok := stackShortNames[language]
|
||||
if !ok {
|
||||
languages := []string{}
|
||||
for k, _ := range stackShortNames {
|
||||
languages = append(languages, k)
|
||||
}
|
||||
|
||||
return errors.New(fmt.Sprintf("Unrecognized lanugage '%v'. Please choose one: %v.", language, strings.Join(languages, ", ")))
|
||||
}
|
||||
|
||||
// set up the command, specifying a sanitized project name and connecting
|
||||
// standard output and error.
|
||||
cmd := exec.Command("appsody", "init", stackName(language), "--project-name", name)
|
||||
cmd := exec.Command("appsody", "init", "boson/"+stackName, "--project-name", name)
|
||||
cmd.Dir = path
|
||||
|
||||
fmt.Println(cmd)
|
||||
|
||||
// If verbose logging is enabled, echo appsody's chatty stdout.
|
||||
if n.Verbose {
|
||||
cmd.Stdout = os.Stdout
|
||||
|
@ -57,7 +78,3 @@ func (n *Initializer) Initialize(name, language, path string) error {
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func stackName(language string) string {
|
||||
return "boson/go"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue