diff options
author | Alex Crawford <wally@code.acrawford.com> | 2021-04-07 16:54:55 -0700 |
---|---|---|
committer | Alex Crawford <wally@code.acrawford.com> | 2021-04-07 17:01:05 -0700 |
commit | 052ec5318c18e7c1983c247863687e333d5c05c8 (patch) | |
tree | fbe09ba800ed4b3c7629e8ee9fb43de15b8891c9 | |
parent | c88466d3522a1777f51bd92105612a6ee3cdfc8e (diff) |
main: add support for parsing file URIs
This is helpful if you want to configure Firefox to automatically run
wally when downloading a firmware image.
-rw-r--r-- | main.go | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -3,11 +3,13 @@ package main import ( "flag" "fmt" - "github.com/caarlos0/spin" - "gopkg.in/cheggaaa/pb.v1" + "net/url" "os" "path/filepath" "time" + + "github.com/caarlos0/spin" + "gopkg.in/cheggaaa/pb.v1" ) var appVersion = "2.0.0" @@ -36,9 +38,20 @@ func main() { os.Exit(2) } - path := flag.Arg(0) - extension := filepath.Ext(path) - if extension != ".bin" && extension != ".hex" { + path := "" + extension := "" + if uri, err := url.Parse(flag.Arg(0)); err == nil { + switch uri.Scheme { + case "", "file": + extension = filepath.Ext(uri.Path) + switch extension { + case ".bin", ".hex": + path = uri.Path + } + } + } + + if path == "" { fmt.Println("Please provide a valid firmware file: a .hex file (ErgoDox EZ) or a .bin file (Moonlander / Planck EZ)") os.Exit(2) } |