mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
chore: Clean up URI handling in crawl command
This commit is contained in:
parent
eccd9adb41
commit
afe84f6129
1 changed files with 8 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -18,10 +19,16 @@ var crawlCmd = &cobra.Command{
|
||||||
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
|
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err := url.ParseRequestURI(args[0])
|
parsedURI, err := url.ParseRequestURI(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid URI specified: %s", args[0])
|
return fmt.Errorf("invalid URI specified: %s", args[0])
|
||||||
}
|
}
|
||||||
|
// Remove any trailing slashes
|
||||||
|
parsedURI.Path = strings.TrimSuffix(parsedURI.Path, "/")
|
||||||
|
// Collapse any doubled slashes
|
||||||
|
parsedURI.Path = strings.ReplaceAll(parsedURI.Path, "//", "/")
|
||||||
|
// Update the URI in the args slice
|
||||||
|
args[0] = parsedURI.String()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue