-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (39 loc) · 1.11 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
package main
import (
"fmt"
"os"
"slices"
"github.com/alecthomas/kong"
"github.com/jonathanhope/armaria/cmd/cli/internal"
"github.com/jonathanhope/armaria/cmd/cli/internal/messaging"
"github.com/jonathanhope/armaria/internal/manifest"
)
var version string
func main() {
// When a browser sends a native message it will send the extension ID as the last argument.
// When we see one of Armaria's extension IDs we switch to native messaging mode.
extensionIds := []string{manifest.FirefoxExtension, manifest.ChromeExtension1, manifest.ChromeExtension2}
hostMode := false
for _, arg := range os.Args {
if slices.Contains(extensionIds, arg) {
hostMode = true
}
}
if hostMode {
if err := messaging.Dispatch(os.Stdin, os.Stdout); err != nil {
fmt.Printf("Unexpected error: %s", err)
os.Exit(1)
}
os.Exit(0)
}
// Otherwise we fall into the standard CLI.
rootCmd := cmd.RootCmdFactory()
ctx := kong.Parse(&rootCmd)
err := ctx.Run(&cmd.Context{
DB: rootCmd.DB,
Formatter: rootCmd.Formatter,
Writer: os.Stdout,
ReturnCode: os.Exit,
Version: version})
ctx.FatalIfErrorf(err)
}