diff 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
line wrap: on
line diff
--- 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)