Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct value for config path and robustify #130

Merged
merged 2 commits into from Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/create.go
Expand Up @@ -23,7 +23,7 @@ func init() {
createCmd.Flags().StringP("path", "p", cwd(), "Path to the new project directory - $FAAS_PATH")
createCmd.Flags().StringP("repository", "r", "", "Repository for built images, ex 'docker.io/myuser' or just 'myuser'. Optional if --image provided. - $FAAS_REPOSITORY")
createCmd.Flags().StringP("runtime", "l", faas.DefaultRuntime, "Function runtime language/framework. - $FAAS_RUNTIME")
createCmd.Flags().StringP("templates", "", filepath.Join(configPath(), "faas", "templates"), "Extensible templates path. - $FAAS_TEMPLATES")
createCmd.Flags().StringP("templates", "", filepath.Join(configPath(), "templates"), "Extensible templates path. - $FAAS_TEMPLATES")
createCmd.Flags().StringP("trigger", "t", faas.DefaultTrigger, "Function trigger (ex: 'http','events') - $FAAS_TRIGGER")

var err error
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Expand Up @@ -16,7 +16,7 @@ func init() {
initCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options - $FAAS_CONFIRM")
initCmd.Flags().StringP("path", "p", cwd(), "Path to the new project directory - $FAAS_PATH")
initCmd.Flags().StringP("runtime", "l", faas.DefaultRuntime, "Function runtime language/framework. - $FAAS_RUNTIME")
initCmd.Flags().StringP("templates", "", filepath.Join(configPath(), "faas", "templates"), "Extensible templates path. - $FAAS_TEMPLATES")
initCmd.Flags().StringP("templates", "", filepath.Join(configPath(), "templates"), "Extensible templates path. - $FAAS_TEMPLATES")
initCmd.Flags().StringP("trigger", "t", faas.DefaultTrigger, "Function trigger (ex: 'http','events') - $FAAS_TRIGGER")

if err := initCmd.RegisterFlagCompletionFunc("runtime", CompleteRuntimeList); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions cmd/root.go
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/mitchellh/go-homedir"
"github.com/ory/viper"
Expand All @@ -11,7 +12,7 @@ import (
"github.com/boson-project/faas"
)

var config = "~/.faas/config" // Location of the optional system-wide config file.
var config = configPath() // Location of the optional system-wide config file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can now be removed, as it's been correctly updated to be directly inlined into the configPath function using filepath to make it OS agnostic.

Indeed it should probably be removed as the configPath() static function should be used preferentially to a global variable.


// The root of the command tree defines the command name, descriotion, globally
// available flags, etc. It has no action of its own, such that running the
Expand Down Expand Up @@ -95,11 +96,15 @@ func cwd() (cwd string) {
// function defaults and extensible templates.
func configPath() (path string) {
if path = os.Getenv("XDG_CONFIG_HOME"); path != "" {
path = filepath.Join(path, "faas")
return
}
path, err := homedir.Expand("~/.config")
home, err := homedir.Expand("~")
if err != nil {
fmt.Fprintf(os.Stderr, "could not derive home directory for use as default templates path: %v", err)
path = filepath.Join(".config", "faas")
} else {
path = filepath.Join(home, ".config", "faas")
}
return
}
Expand Down