From 1c757f61a5232b13259874a535fe9aa52429a7d6 Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Tue, 13 Feb 2018 11:28:00 -0500 Subject: [PATCH] Add input cleaner This should allow things like http urls to be passed in and turned into proper references --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index fff4790..a90c731 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,14 @@ 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(p string) string { + re := regexp.MustCompile(`^.*(/ip(f|n)s/.+)$`) + matches := re.FindStringSubmatch(s) + if len(matches) > 1 { + return matches[1] + } + return p +}