Skip to content

Commit

Permalink
Add input cleaner
Browse files Browse the repository at this point in the history
This should allow things like http urls to be passed in and turned into
proper references
  • Loading branch information
Dominic Della Valle committed Feb 13, 2018
1 parent 922c6f4 commit 1c757f6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/signal"
"regexp"
"strings"
"syscall"

Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
}

0 comments on commit 1c757f6

Please sign in to comment.