Skip to content

Commit

Permalink
refactor: optimize subcommand 'config'
Browse files Browse the repository at this point in the history
  • Loading branch information
windvalley committed Feb 14, 2022
1 parent f5f9fda commit 16b359b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions configs/gossh.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
auth:
# Default login user.
# Default: $USER
user: "xg"
user: ""

# Default password of the login user.
# Default: ""
Expand Down Expand Up @@ -47,9 +47,10 @@ run:
# Default: root
as-user: root

# Export systems environment variables LANG/LC_ALL/LANGUAGE
# Export systems environment variables LANG/LC_ALL/LANGUAGE
# as this value when executing command/script.
# Default: original variables values of the target hosts
# Available vaules: zh_CN.UTF-8, en_US.UTF-8, etc.
# Default: "" (null means do not export)
lang: ""

# Number of concurrent connections.
Expand Down
12 changes: 9 additions & 3 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -80,10 +81,10 @@ run:
# Default: root
as-user: %s
# Export systems environment variables LANG/LC_ALL/LANGUAGE
# Export systems environment variables LANG/LC_ALL/LANGUAGE
# as this value when executing command/script.
# Available vaules: zh_CN.UTF-8, en_US.UTF-8, etc.
# Default: "" (do not export)
# Default: "" (null means do not export)
lang: %q
# Number of concurrent connections.
Expand Down Expand Up @@ -167,9 +168,14 @@ and $PWD/.gossh.yaml has higher priority than $HOME/.gossh.yaml`,
Run: func(cmd *cobra.Command, args []string) {
config := configflags.Config

user := config.Auth.User
if user == os.Getenv("USER") {
user = ""
}

fmt.Printf(
configTemplate,
config.Auth.User, config.Auth.Password, config.Auth.AskPass,
user, config.Auth.Password, config.Auth.AskPass,
config.Auth.PassFile, config.Auth.Passphrase, config.Auth.VaultPassFile,
config.Hosts.Inventory, config.Hosts.Port,
config.Run.Sudo, config.Run.AsUser, config.Run.Lang, config.Run.Concurrency,
Expand Down

0 comments on commit 16b359b

Please sign in to comment.