mirror of
https://github.com/coalaura/up.git
synced 2025-07-18 21:53:23 +00:00
resolve hosts
This commit is contained in:
42
client/hosts.go
Normal file
42
client/hosts.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/kevinburke/ssh_config"
|
||||
)
|
||||
|
||||
func SSHConfigPath() (string, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return filepath.Join(home, ".ssh", "config"), nil
|
||||
}
|
||||
|
||||
func LoadSSHConfig() (*ssh_config.Config, error) {
|
||||
path, err := SSHConfigPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return new(ssh_config.Config), nil
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(path, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
cfg, err := ssh_config.Decode(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
@ -23,25 +23,17 @@ var (
|
||||
|
||||
func main() {
|
||||
app := &cli.Command{
|
||||
Name: "up",
|
||||
Usage: "UP client",
|
||||
Version: Version,
|
||||
Name: "up",
|
||||
Usage: "UP client",
|
||||
Version: Version,
|
||||
ArgsUsage: "<file> <host>",
|
||||
UsageText: "up [options] <file> <host>",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "key",
|
||||
Aliases: []string{"k"},
|
||||
Name: "identity",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "private key file for authentication",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "file",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "file to upload",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "target",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "target to upload to",
|
||||
},
|
||||
},
|
||||
Action: run,
|
||||
EnableShellCompletion: true,
|
||||
|
Reference in New Issue
Block a user