feat: add TALOSCONFIG env var (#422)

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
This commit is contained in:
Andrew Rynhard 2019-02-25 15:06:49 -08:00 committed by GitHub
parent c43e4db85d
commit c63ef4477b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import (
"os/user"
"path"
"github.com/autonomy/talos/internal/pkg/constants"
"github.com/spf13/cobra"
)
@ -37,11 +38,18 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
u, err := user.Current()
if err != nil {
return
var (
defaultTalosConfig string
ok bool
)
if defaultTalosConfig, ok = os.LookupEnv(constants.TalosConfigEnvVar); !ok {
u, err := user.Current()
if err != nil {
return
}
defaultTalosConfig = path.Join(u.HomeDir, ".talos", "config")
}
rootCmd.PersistentFlags().StringVar(&talosconfig, "talosconfig", path.Join(u.HomeDir, ".talos", "config"), "The path to the Talos configuration file")
rootCmd.PersistentFlags().StringVar(&talosconfig, "talosconfig", defaultTalosConfig, "The path to the Talos configuration file")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)

View File

@ -99,6 +99,9 @@ const (
// SystemContainerdNamespace is the Containerd namespace for Talos services.
SystemContainerdNamespace = "system"
// TalosConfigEnvVar is the environment variable for setting the Talos configuration file path.
TalosConfigEnvVar = "TALOSCONFIG"
)
// See https://linux.die.net/man/3/klogctl