Skip to content

Commit

Permalink
Revert "Parse config path"
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh authored Oct 11, 2017
1 parent bcb1868 commit f85c397
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
12 changes: 6 additions & 6 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
)

func list(c *cli.Context) error {
hosts, _ := sshconfig.ParseSSHConfig(parsePath(path))
hosts, _ := sshconfig.ParseSSHConfig(path)
if len(c.Args()) > 0 {
searchHosts := []*sshconfig.SSHHost{}
for _, host := range hosts {
Expand All @@ -46,7 +46,7 @@ func add(c *cli.Context) error {
}
newAlias := c.Args().Get(0)
hostStr := c.Args().Get(1)
hosts, _ := sshconfig.ParseSSHConfig(parsePath(path))
hosts, _ := sshconfig.ParseSSHConfig(path)
if _, err := checkAlias(hosts, false, newAlias); err != nil {
printErrorFlag()
return cli.NewExitError(err, 1)
Expand Down Expand Up @@ -74,7 +74,7 @@ func update(c *cli.Context) error {
}
alias := c.Args().Get(0)
hostStr := c.Args().Get(1)
hosts, _ := sshconfig.ParseSSHConfig(parsePath(path))
hosts, _ := sshconfig.ParseSSHConfig(path)
host, err := checkAlias(hosts, true, alias)
if err != nil {
printErrorFlag()
Expand Down Expand Up @@ -127,7 +127,7 @@ func delete(c *cli.Context) error {
if err := argumentsCheck(c, 1, -1); err != nil {
return printErrorWithHelp(c, err)
}
hosts, _ := sshconfig.ParseSSHConfig(parsePath(path))
hosts, _ := sshconfig.ParseSSHConfig(path)
if _, err := checkAlias(hosts, true, c.Args()...); err != nil {
printErrorFlag()
return cli.NewExitError(err, 1)
Expand Down Expand Up @@ -187,7 +187,7 @@ func open(c *cli.Context) error {
}

alias := c.Args().Get(0)
hosts, _ := sshconfig.ParseSSHConfig(parsePath(path))
hosts, _ := sshconfig.ParseSSHConfig(path)
if _, err := checkAlias(hosts, true, alias); err != nil {
printErrorFlag()
return cli.NewExitError(err, 1)
Expand All @@ -213,7 +213,7 @@ func run(c *cli.Context) error {
}
alias := c.Args().Get(0)
command := c.Args().Get(1)
hosts, _ := sshconfig.ParseSSHConfig(parsePath(path))
hosts, _ := sshconfig.ParseSSHConfig(path)
host, err := checkAlias(hosts, true, alias)
if err != nil {
printErrorFlag()
Expand Down
21 changes: 0 additions & 21 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@ var (
errorColor = color.New(color.BgRed, color.FgWhite)
)

// parsePath resolve path and get the real file path, if config file is a symbol link
func parsePath(path string) string {
fileInfo, err := os.Lstat(path)

if err != nil {
fmt.Println(err)
os.Exit(1)
}

if fileInfo.Mode()&os.ModeSymlink != 0 {
originFile, err := os.Readlink(path)

if err != nil {
fmt.Println(err)
os.Exit(1)
}
return originFile
}
return path
}

func saveHosts(hosts []*sshconfig.SSHHost) error {
var buffer bytes.Buffer
for _, host := range hosts {
Expand Down

0 comments on commit f85c397

Please # to comment.