1
0
mirror of https://github.com/coalaura/up.git synced 2025-07-18 21:53:23 +00:00

resolve hosts

This commit is contained in:
Laura
2025-06-20 19:03:14 +02:00
parent 11dc57ea01
commit 2e2bf5f7e6
4 changed files with 52 additions and 15 deletions

42
client/hosts.go Normal file
View 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
}

View File

@ -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,