Mercurial > repos > public > wdown
changeset 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 |
files | test.md wdown.go |
diffstat | 2 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/test.md Tue Jun 16 21:11:38 2020 +0200 +++ b/test.md Tue Jun 16 21:23:38 2020 +0200 @@ -26,7 +26,7 @@ ## TODO Some things need doing - [x] Build the simplest possible markdown commandline utility - - [ ] Add commandling argument parsing + - [x] Add command-line argument parsing - [ ] Allow template file as an input ### Code highlighting
--- a/wdown.go Tue Jun 16 21:11:38 2020 +0200 +++ b/wdown.go Tue Jun 16 21:23:38 2020 +0200 @@ -1,6 +1,8 @@ package main import ( + "flag" + "fmt" "io/ioutil" "log" "os" @@ -12,7 +14,14 @@ ) func main() { - source, err := ioutil.ReadFile(os.Args[1]) + flag.Parse() + + if flag.NArg() < 1 { + fmt.Println("Please provide a markdown file for parsing.") + os.Exit(1) + } + + source, err := ioutil.ReadFile(flag.Arg(0)) if err != nil { log.Fatal(err)