Mercurial > repos > public > wdown
comparison wdown.go @ 5:534fa4c6668e
Add command line argument parsing
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 16 Jun 2020 21:23:38 +0200 |
parents | 0b747e2d51c9 |
children | a5f397e25cb7 |
comparison
equal
deleted
inserted
replaced
4:0b747e2d51c9 | 5:534fa4c6668e |
---|---|
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "flag" | |
5 "fmt" | |
4 "io/ioutil" | 6 "io/ioutil" |
5 "log" | 7 "log" |
6 "os" | 8 "os" |
7 | 9 |
8 "github.com/yuin/goldmark" | 10 "github.com/yuin/goldmark" |
10 "github.com/yuin/goldmark/extension" | 12 "github.com/yuin/goldmark/extension" |
11 "github.com/yuin/goldmark/parser" | 13 "github.com/yuin/goldmark/parser" |
12 ) | 14 ) |
13 | 15 |
14 func main() { | 16 func main() { |
15 source, err := ioutil.ReadFile(os.Args[1]) | 17 flag.Parse() |
18 | |
19 if flag.NArg() < 1 { | |
20 fmt.Println("Please provide a markdown file for parsing.") | |
21 os.Exit(1) | |
22 } | |
23 | |
24 source, err := ioutil.ReadFile(flag.Arg(0)) | |
16 | 25 |
17 if err != nil { | 26 if err != nil { |
18 log.Fatal(err) | 27 log.Fatal(err) |
19 } | 28 } |
20 | 29 |