forked from trntv/sshed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
97 lines (80 loc) · 1.76 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"os"
"os/user"
"path/filepath"
"github.com/maiko/sshed/commands"
"github.com/maiko/sshed/keychain"
"github.com/maiko/sshed/ssh"
"github.com/mgutz/ansi"
"github.com/urfave/cli"
)
var version, build string
func main() {
app := cli.NewApp()
app.Name = "sshed"
app.Usage = "SSH config editor and hosts manager"
app.Authors = []cli.Author{
{
Name: "Eugene Terentev",
Email: "eugene@terentev.net",
},
{
Name: "Maiko BOSSUYT",
Email: "hello@maiko-bossuyt.eu",
},
}
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", "keychain"),
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: "ssh-path",
EnvVar: "SSHED_SSH_BIN",
Value: "ssh",
Usage: "path to SSH binary",
},
cli.StringFlag{
Name: "scp-path",
EnvVar: "SSHED_SCP_BIN",
Value: "scp",
Usage: "path to SCP 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)
}
}