Skip to content

Commit

Permalink
Accept stack.yaml as a default file if present
Browse files Browse the repository at this point in the history
Requested by @welteki, if stack.yml is present then it is
taken to be the default with a --yaml/-f argument being needed.

This change also looks for stack.yaml as a valid alternative
name.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jan 23, 2025
1 parent e3c149a commit 04a590c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions commands/faas.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
)

const (
defaultGateway = "http://127.0.0.1:8080"
defaultNetwork = ""
defaultYAML = "stack.yml"
defaultGateway = "http://127.0.0.1:8080"
defaultNetwork = ""
defaultYML = "stack.yml"
defaultYAML = "stack.yaml"

defaultSchemaVersion = "1.0"
)

Expand Down Expand Up @@ -144,6 +146,8 @@ func checkAndSetDefaultYaml() {
// Check if there is a default yaml file and set it
if _, err := stat(defaultYAML); err == nil {
yamlFile = defaultYAML
} else if _, err := stat(defaultYML); err == nil {
yamlFile = defaultYML
}
}

Expand Down
6 changes: 3 additions & 3 deletions commands/faas_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"io/ioutil"
"io"
"os"
"testing"
)
Expand All @@ -11,15 +11,15 @@ var mockStatParams string
func setupFaas(statError error) {
yamlFile = ""
mockStatParams = ""
faasCmd.SetOutput(ioutil.Discard)
faasCmd.SetOutput(io.Discard)

stat = func(f string) (os.FileInfo, error) {
mockStatParams = f
return nil, statError
}
}

func TestCallsStatWithDefaulYAMLFileName(t *testing.T) {
func TestCallsStatWithDefaultYAMLFileName(t *testing.T) {
setupFaas(nil)

Execute([]string{"help"})
Expand Down
2 changes: 1 addition & 1 deletion commands/template_store_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func getTemplateInfo(repository string) ([]TemplateInfo, error) {

templatesInfo := []TemplateInfo{}
if err := json.Unmarshal(body, &templatesInfo); err != nil {
return nil, fmt.Errorf("can't unmarshal text: %s", err.Error())
return nil, fmt.Errorf("can't unmarshal text: %s, value: %s", err.Error(), string(body))
}

sortTemplates(templatesInfo)
Expand Down

0 comments on commit 04a590c

Please sign in to comment.