summaryrefslogtreecommitdiff
path: root/cmd/localclient/main.go
blob: d0b7e419c2571828a199c3c73accb48bb47e4e6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"strings"

	"git.brandonirizarry.xyz/links/internal/findlinks"
)

func main() {
	// Set up logging.
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	// Retrieve the CLI flags, and check them.
	filename := flag.String("file", "", "Local HTML file")
	flag.Parse()

	if *filename == "" {
		log.Fatal("Missing -file argument")
	}

	// FIXME: .htm is possible as well, but I'm skipping that for
	// now. Also, we could look into templates and that sort of
	// thing at some point.
	if !strings.HasSuffix(*filename, ".html") {
		log.Fatal("Need HTML file (.html)")
	}

	// Open the local file.
	f, err := os.Open(*filename)
	if err != nil {
		log.Fatalf("can't open %s: %v", *filename, err)
	}
	defer f.Close()

	links, err := findlinks.FindLinks(f)
	if err != nil {
		log.Fatal(err)
	}

	for _, link := range links {
		fmt.Printf("%s\n\n", findlinks.Format(link, "\n"))
	}
}