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 +}