From 2e2bf5f7e675514b9cd182edbfdcbc742291eafb Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 20 Jun 2025 19:03:14 +0200 Subject: [PATCH] resolve hosts --- client/hosts.go | 42 ++++++++++++++++++++++++++++++++++++++++++ client/main.go | 22 +++++++--------------- go.mod | 1 + go.sum | 2 ++ 4 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 client/hosts.go diff --git a/client/hosts.go b/client/hosts.go new file mode 100644 index 0000000..7a4e6aa --- /dev/null +++ b/client/hosts.go @@ -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 +} diff --git a/client/main.go b/client/main.go index 88c9f14..2162ebb 100644 --- a/client/main.go +++ b/client/main.go @@ -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: " ", + UsageText: "up [options] ", 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, diff --git a/go.mod b/go.mod index 1841a81..7425e86 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.24.2 require ( github.com/coalaura/logger v1.4.5 github.com/go-chi/chi/v5 v5.2.2 + github.com/kevinburke/ssh_config v1.2.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/urfave/cli/v3 v3.3.8 github.com/vmihailenco/msgpack/v5 v5.4.1 diff --git a/go.sum b/go.sum index 6bb58f2..5cff3f4 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618= github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=