@@ -4,24 +4,26 @@ import (
44 "encoding/base64"
55 "errors"
66 "fmt"
7- "gopkg.in/yaml.v2"
87 "io/ioutil"
98 "log"
109 "os"
1110 "strings"
11+
12+ "gopkg.in/yaml.v2"
1213)
1314
1415type SshConfigs struct {
1516 Config map [string ]SshConfig
1617}
1718
1819type SshConfig struct {
19- Hostname string `yaml:"hostname"`
20- User string `yaml:"user"`
21- Password string `yaml:"password"`
22- Port string `yaml:"port"`
23- Key string `yaml:"key"`
24- Alias string `yaml:"alias"`
20+ Hostname string `yaml:"hostname"`
21+ User string `yaml:"user"`
22+ Password string `yaml:"password"`
23+ Port string `yaml:"port"`
24+ Key string `yaml:"key"`
25+ DefaultUser bool `yaml:"default_user"`
26+ Alias string `yaml:"alias"`
2527}
2628
2729func ReadYaml () (SshConfigs , error ) {
@@ -73,6 +75,15 @@ func ReadYaml() (SshConfigs, error) {
7375 configs [config [i ].Alias ] = config [i ]
7476 }
7577
78+ configs [fmt .Sprintf ("%v@%v" , config [i ].User , config [i ].Hostname )] = config [i ]
79+
80+ if config [i ].DefaultUser {
81+ _ , found := configs [config [i ].Hostname ]
82+ if found {
83+ log .Fatalln ("duplicated hostname found for" , config [i ].Hostname )
84+ }
85+ configs [config [i ].Hostname ] = config [i ]
86+ }
7687 }
7788 }
7889 if len (configs ) == 0 {
0 commit comments