Skip to content

Commit

Permalink
Allow setting default parameters with env vars
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Oct 1, 2019
1 parent db694f1 commit 23ae760
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions cmd/podman/main_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,44 @@
package main

import (
"github.com/pkg/errors"
"os"
"os/user"
"strconv"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

const remote = true

func init() {
var username string
if curruser, err := user.Current(); err == nil {
username = curruser.Username
if username = os.Getenv("PODMAN_USER"); username == "" {
if curruser, err := user.Current(); err == nil {
username = curruser.Username
}
}
host := os.Getenv("PODMAN_HOST")
port := 22
if portstr := os.Getenv("PODMAN_PORT"); portstr != "" {
if p, err := strconv.Atoi(portstr); err == nil {
port = p
}
}
key := os.Getenv("PODMAN_IDENTITY_FILE")
ignore := false
if ignorestr := os.Getenv("PODMAN_IGNORE_HOSTS"); ignorestr != "" {
if b, err := strconv.ParseBool(ignorestr); err == nil {
ignore = b
}
}
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.ConnectionName, "connection", "", "remote connection name")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteConfigFilePath, "remote-config-path", "", "alternate path for configuration file")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteUserName, "username", username, "username on the remote host")
rootCmd.PersistentFlags().IntVar(&MainGlobalOpts.Port, "port", 22, "port on remote host")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteHost, "remote-host", "", "remote host")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.IdentityFile, "identity-file", "", "identity-file")
rootCmd.PersistentFlags().BoolVar(&MainGlobalOpts.IgnoreHosts, "ignore-hosts", false, "ignore hosts")
rootCmd.PersistentFlags().IntVar(&MainGlobalOpts.Port, "port", port, "port on remote host")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteHost, "remote-host", host, "remote host")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.IdentityFile, "identity-file", key, "identity-file")
rootCmd.PersistentFlags().BoolVar(&MainGlobalOpts.IgnoreHosts, "ignore-hosts", ignore, "ignore hosts")
// TODO maybe we allow the altering of this for bridge connections?
// rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.VarlinkAddress, "varlink-address", adapter.DefaultAddress, "address of the varlink socket")
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.LogLevel, "log-level", "error", "Log messages above specified level: debug, info, warn, error, fatal or panic. Logged to ~/.config/containers/podman.log")
Expand Down

0 comments on commit 23ae760

Please sign in to comment.