Skip to content

Commit

Permalink
Add -d flag. Bump version to 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lixvbnet committed Apr 15, 2022
1 parent aac3337 commit 9ef9748
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DIST_DIR = dist
NAME = $(shell basename $$PWD)
VER = 1.0
VER = 1.1
LD_FLAGS = -X 'main.Name=$(NAME)' -X 'main.Version=$(VER)' -X 'main.GitHash=`git rev-parse --short=8 HEAD`'

build:
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
U = flag.String("u", "", "user")
PASS = flag.Bool("pass", false, "enter password promptly")
T = flag.Bool("t", false, "request terminal")
D = flag.Bool("d", false, "for empty values, only cover with defaults, logins section will not be used")

templates = &promptui.SelectTemplates{
Label: "✨ {{ . | green}}",
Expand Down Expand Up @@ -91,7 +92,7 @@ func main() {
if target == "" {
chosen = choose(config.Nodes)
}
node := sshlib.GetNode(config, target, chosen, overrider)
node := sshlib.GetNode(config, target, chosen, *D, overrider)
if node == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion sshlib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestGetNode(t *testing.T) {

for _, test := range tests {
c := getConfig()
if got := GetNode(c, test.target, &test.chosen, &test.overrider); *got != test.want {
if got := GetNode(c, test.target, &test.chosen, false, &test.overrider); *got != test.want {
t.Errorf("\n//desc: %v\ntarget: %v\nchosen: %v\noverrider: %v\nwant: %v\ngot: %v\n",
test.desc, test.target, test.chosen, test.overrider, test.want, got)
}
Expand Down
5 changes: 3 additions & 2 deletions sshlib/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import "strings"

// Get node from target, or choose from menu, and then override fields with overrider.
// chosen will be ignored if target is not empty.
// If defaultsOnly is set to true, empty values will only be covered with defaults, logins section will not be used.
// Values in overrider have top priority.
func GetNode(config *Config, target string, chosen *Node, overrider *Node) (node *Node) {
func GetNode(config *Config, target string, chosen *Node, defaultsOnly bool, overrider *Node) (node *Node) {
if target != "" {
node = parseTarget(config, target)
} else {
Expand All @@ -21,7 +22,7 @@ func GetNode(config *Config, target string, chosen *Node, overrider *Node) (node
}

if config != nil {
if config.Settings != nil {
if !defaultsOnly && config.Settings != nil {
node.SetLogin(config.Settings.Logins, target == "") // override if target is empty (i.e. using chosen)
}
node.SetDefaults(config.Defaults, config.Settings)
Expand Down

0 comments on commit 9ef9748

Please sign in to comment.