diff options
author | Teddy Wing | 2023-11-14 01:53:02 +0100 |
---|---|---|
committer | Teddy Wing | 2023-11-14 01:53:02 +0100 |
commit | c6a33a3e878504423c65210a629837cf14cee4e6 (patch) | |
tree | 2ffb717d3ae1d0591c1631a28044e1b60d5d3455 | |
parent | 8d8fa84f4f336f7a2e43acf7ca0c417299df8f8b (diff) | |
download | swextreload-c6a33a3e878504423c65210a629837cf14cee4e6.tar.bz2 |
main: Print errors on `--socket-url` and extension IDs missing
In order to print a custom error message for missing extension IDs, I
needed to set a default value for it.
Looks like the type assertions are necessary. Not the cleanest, but no
matter.
-rw-r--r-- | cmd/swextreload/main.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/cmd/swextreload/main.go b/cmd/swextreload/main.go index b1702f6..916b6a8 100644 --- a/cmd/swextreload/main.go +++ b/cmd/swextreload/main.go @@ -1,7 +1,9 @@ package main import ( + "fmt" "log" + "os" "git.sr.ht/~liliace/claw" swextreload "gopkg.teddywing.com/swextreload/internal" @@ -31,10 +33,11 @@ func main() { }, Positionals: []claw.Positional{ { - Name: "extension_id", - Type: "string", - Repeating: true, - Description: "extensions to reload", + Name: "extension_id", + Type: "string", + Repeating: true, + DefaultValue: []string{}, + Description: "extensions to reload", }, }, }) @@ -43,11 +46,26 @@ func main() { } log.Printf("args: %#v", args) + + socket_url, ok := args["socket-url"].(string) + if !ok { + fmt.Println("error: '--socket-url' is required") + os.Exit(64) + } + + extension_ids := args["extension_id"].([]string) + if len(extension_ids) == 0 { + fmt.Println("error: missing extension IDs") + os.Exit(64) + } + return err = swextreload.Reload( - "ws://127.0.0.1:55755/devtools/browser/4536efdf-6ddf-40b6-9a16-258a1935d866", - "imcibeelfmccdpnnlemllnepgbfdbkgo", + // "ws://127.0.0.1:55755/devtools/browser/4536efdf-6ddf-40b6-9a16-258a1935d866", + // "imcibeelfmccdpnnlemllnepgbfdbkgo", + socket_url, + extension_ids[0], true, ) if err != nil { |