-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
68 lines (59 loc) · 1.4 KB
/
main.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
package main
import (
"fmt"
"log"
"log/slog"
"os"
"github.com/d3witt/viking/cli/command"
"github.com/d3witt/viking/cli/command/cfg"
"github.com/d3witt/viking/cli/command/key"
"github.com/d3witt/viking/cli/command/machine"
"github.com/d3witt/viking/config"
"github.com/d3witt/viking/streams"
"github.com/urfave/cli/v2"
)
var version = "dev" // set by build script
func main() {
c, err := config.ParseDefaultConfig()
if err != nil {
fmt.Println(err.Error())
return
}
cmdLogger := slog.New(command.NewCmdLogHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
vikingCli := &command.Cli{
Config: &c,
In: streams.StdIn,
Out: streams.StdOut,
Err: streams.StdErr,
CmdLogger: cmdLogger,
}
app := &cli.App{
Name: "viking",
Usage: "Manage your SSH keys and remote machines",
Version: version,
Commands: []*cli.Command{
// Often used commands
machine.NewExecuteCmd(vikingCli),
machine.NewCopyCmd(vikingCli),
// Other commands
key.NewCmd(vikingCli),
machine.NewCmd(vikingCli),
cfg.NewConfigCmd(vikingCli),
},
Suggest: true,
Reader: vikingCli.In,
Writer: vikingCli.Out,
ErrWriter: vikingCli.Err,
ExitErrHandler: func(ctx *cli.Context, err error) {
if err != nil {
fmt.Fprintf(vikingCli.Err, "Error: %v\n", err)
os.Exit(0)
}
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}