Skip to content

Commit

Permalink
Add input checker
Browse files Browse the repository at this point in the history
This should allow things like gateway urls to be passed in and turned into proper references
  • Loading branch information
djdv committed Jan 31, 2019
1 parent 796cbc7 commit 4d1ddfb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 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,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
}

0 comments on commit 4d1ddfb

Please sign in to comment.