summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2024-12-21 19:40:14 +0900
committerhaturatu <taro@eyes4you.org>2024-12-21 19:40:14 +0900
commit011d011d818b7d1eae512942f3721e57a26d8a7b (patch)
tree035914a3985376ba809e2490ed2b49b43367b459 /main.go
parentdf23b04506e6b4cdfa5c40ce52172728bfe1d063 (diff)
add : output md
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/main.go b/main.go
index 221783f..e5cfd93 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"crypto/tls"
+ "flag"
"fmt"
"net/http"
"os"
@@ -85,17 +86,32 @@ func fetchTitle(url string) (string, error) {
}
func main() {
- if len(os.Args) < 2 {
- fmt.Fprintln(os.Stderr, "Usage: ght \"https://google.com/\"")
+ markdown := flag.Bool("m", false, "Output the URL in Markdown format")
+
+ flag.Usage = func() {
+ fmt.Fprintf(os.Stderr, "Usage: %s [options] <URL>\n", os.Args[0])
+ fmt.Fprintln(os.Stderr, "Options:")
+ flag.PrintDefaults()
+ }
+
+ flag.Parse()
+
+ if flag.NArg() < 1 {
+ flag.Usage()
os.Exit(1)
}
- url := os.Args[1]
+ url := flag.Arg(0)
title, err := fetchTitle(url)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(2)
}
- fmt.Printf("%s\n", title)
+ // output md
+ if *markdown {
+ fmt.Printf("[%s](%s)\n", title, url)
+ } else {
+ fmt.Printf("%s\n", title)
+ }
}