diff --git a/cmd/pastes/main.go b/cmd/pastes/main.go index ae82465..bd1e268 100644 --- a/cmd/pastes/main.go +++ b/cmd/pastes/main.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "net/url" "os" "strings" @@ -64,6 +65,19 @@ func GetPaste(c *cli.Context) error { pasteID := c.Args().First() rawOutput := c.Bool("raw") + urlFlag := c.Bool("url") + + if urlFlag { + parsedURL, err := url.Parse(pasteID) + if err != nil { + return fmt.Errorf("invalid URL: %v", err) + } + parts := strings.Split(strings.Trim(parsedURL.Path, "/"), "/") + if len(parts) == 0 || parts[0] == "" { + return fmt.Errorf("failed to extract paste id from URL") + } + pasteID = parts[0] + } req, err := http.NewRequest("GET", fmt.Sprintf("%s/pastes/%s", API_BASE_URL, pasteID), nil) if err != nil { diff --git a/main.go b/main.go index 4a43880..796b183 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,11 @@ func main() { Aliases: []string{"r"}, Usage: "Display raw content only", }, + &cli.BoolFlag{ + Name: "url", + Aliases: []string{"u"}, + Usage: "Is the paste_id a URL", + }, }, }, },