From 3be014a4a891d57f27f1931cacf2b64517a4ec1d Mon Sep 17 00:00:00 2001 From: blank X Date: Tue, 8 Feb 2022 16:57:14 +0700 Subject: [PATCH] Add optional link argument --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4155c75..ee2d8cb 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,8 @@ import ( ) func main() { - if len(os.Args) != 2 { - fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args[0]) + if len(os.Args) != 2 && len(os.Args) != 3 { + fmt.Fprintf(os.Stderr, "Usage: %s [direct url to download instead of inferring from the post]\n", os.Args[0]) os.Exit(1) } LoadMimetypes() @@ -215,7 +215,11 @@ func main() { break } } - unparsedUrl = urls[i] + if len(os.Args) == 3 { + unparsedUrl = os.Args[2] + } else { + unparsedUrl = urls[i] + } response, err := client.Get(unparsedUrl) if err != nil { fmt.Fprintf(os.Stderr, "Failed to get response: %s\n", err)