From 4d1ddfbe91fc0821695e87e754681f31c5920caa Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Tue, 13 Feb 2018 11:28:00 -0500 Subject: [PATCH] Add input checker This should allow things like gateway urls to be passed in and turned into proper references --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index c094b95..3393d7b 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/signal" + "regexp" "strings" "syscall" @@ -37,6 +38,7 @@ func main() { outfile := c.String("output") arg := c.Args().First() + arg = cleanIPFSPath(arg) // Use the final segment of the object's path if no path was given. if outfile == "" { @@ -132,3 +134,13 @@ func movePostfixOptions(args []string) []string { // append extracted arguments to the real args return append(args, the_args...) } + +// cleanIPFSPath attempts to extract an IPFS reference from a string +// if it can't find one it returns the input string +func cleanIPFSPath(path string) string { + matches := regexp.MustCompile(`^.*(/ip(f|n)s/.+)$`).FindStringSubmatch(path) + if len(matches) > 1 { + return matches[1] + } + return path +}