forked from trntv/sshed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
82 lines (66 loc) · 1.51 KB
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"github.com/mgutz/ansi"
"github.com/trntv/sshed/commands"
"github.com/trntv/sshed/keychain"
"github.com/trntv/sshed/ssh"
"github.com/urfave/cli"
"os"
"os/user"
"path/filepath"
)
var version, build string
func main() {
app := cli.NewApp()
app.Name = "sshed"
app.Usage = "SSH config editor and hosts manager"
app.Author = "Eugene Terentev"
app.Email = "eugene@terentev.net"
if version != "" && build != "" {
app.Version = fmt.Sprintf("%s (build %s)", version, build)
}
usr, _ := user.Current()
homeDir := usr.HomeDir
app.HelpName = "help"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "keychain",
EnvVar: "SSHED_KEYCHAIN",
Value: filepath.Join(homeDir, ".sshed"),
Usage: "path to keychain database",
},
cli.StringFlag{
Name: "config",
EnvVar: "SSHED_CONFIG_FILE",
Value: filepath.Join(homeDir, ".ssh", "config"),
Usage: "path to SSH config file",
},
cli.StringFlag{
Name: "bin",
EnvVar: "SSHED_BIN",
Value: "ssh",
Usage: "path to SSH binary",
},
}
app.EnableBashCompletion = true
app.Before = func(context *cli.Context) error {
if context.Command.Name == "help" {
return nil
}
var err error
ssh.Config, err = ssh.Parse(context.String("config"))
if err != nil {
return err
}
dbpath := context.String("keychain")
err = keychain.Open(dbpath)
return err
}
commands.RegisterCommands(app)
err := app.Run(os.Args)
if err != nil {
fmt.Println(ansi.Red, fmt.Sprintf("Error: %s", err))
os.Exit(1)
}
}