From 5a8760ae2321bbefcc1013c67bc490202b7d3c97 Mon Sep 17 00:00:00 2001 From: Carl Kittelberger Date: Thu, 7 Sep 2017 12:00:57 +0200 Subject: [PATCH] Implement better CLI using kingpin. --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f293872..67793f8 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,8 @@ import ( "io/ioutil" "log" "os" + + "gopkg.in/alecthomas/kingpin.v2" ) const ( @@ -20,6 +22,12 @@ const ( InstLoopEnd = ']' ) +var ( + app = kingpin.New("gobfy", "Yet another interpreter for Brainfuck programs.") + + argInput = app.Arg("input", "The source file of the program to execute.").Required().ExistingFile() +) + const ( DefaultPageSize = 1024 ) @@ -200,7 +208,9 @@ func (p *Processor) ExpectEnd() { } func main() { - inputFilePath := os.Args[1] + kingpin.MustParse(app.Parse(os.Args[1:])) + + inputFilePath := *argInput // Open BF source code input, err := ioutil.ReadFile(inputFilePath)