Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Nov 13, 2017
1 parent 283b93b commit e328181
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions sshconfig/sshconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
)

const (
User = "user"
// User is ssh config key
User = "user"
// Hostname is ssh config key
Hostname = "hostname"
Port = "port"
// Port is ssh config key
Port = "port"
)

// ParseConfig parse configs from ssh config file, return config object and alias map
Expand Down
13 changes: 11 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ import (
"github.com/kevinburke/ssh_config"
)

// HostConfig struct include alias, connect string and other config
type HostConfig struct {
// Aliases may be multi, eg "a1 a2"
Aliases string
// Connect format is user@host:port
Connect string
Config map[string]string
// Config is other configs
Config map[string]string
}

// FormatConnect return connect string
func FormatConnect(user, hostname, port string) string {
return fmt.Sprintf("%s@%s:%s", user, hostname, port)
}

// format is [user@]host[:port]
// ParseConnct parse connect string, format is [user@]host[:port]
func ParseConnct(connect string) (string, string, string) {
var u, hostname, port string
port = "22"
Expand All @@ -46,6 +51,7 @@ func ParseConnct(connect string) (string, string, string) {
return u, hostname, port
}

// ArgumentsCheck check arguments count correctness
func ArgumentsCheck(argCount, min, max int) error {
var err error
if min > 0 && argCount < min {
Expand All @@ -57,6 +63,7 @@ func ArgumentsCheck(argCount, min, max int) error {
return err
}

// Query values contains keys
func Query(values, keys []string) bool {
for _, key := range keys {
if !contains(values, key) {
Expand All @@ -75,6 +82,7 @@ func contains(values []string, key string) bool {
return false
}

// GetHomeDir return user's home directory
func GetHomeDir() string {
user, err := user.Current()
if nil == err && user.HomeDir != "" {
Expand All @@ -83,6 +91,7 @@ func GetHomeDir() string {
return os.Getenv("HOME")
}

// CheckAlias check alias expect exist
func CheckAlias(aliasMap map[string]*ssh_config.Host, expectExist bool, aliases ...string) error {
for _, alias := range aliases {
ok := aliasMap[alias] != nil
Expand Down

0 comments on commit e328181

Please # to comment.