From 4d9bd20ea82d483923b8f2d4e59500b378d224c9 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 27 May 2021 10:51:44 +0200 Subject: Update CLI Interface --- main.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index b4d52cf..004fbf3 100644 --- a/main.go +++ b/main.go @@ -6,16 +6,25 @@ import ( "runtime" "log" "flag" + "io/ioutil" ) +type cliArgs struct { + filePath string + debugOutput bool +} + func main() { - // read command line arguments - var stlFilePath string - parseFlags(&stlFilePath) + // read command line arguments and mute log if necessary + var args cliArgs + args.read() + if !args.debugOutput { + log.SetOutput(ioutil.Discard) + } // parse STL file - stl, err := ReadBinaryStlFile(stlFilePath) + stl, err := ReadBinaryStlFile(args.filePath) if err != nil { log.Fatal(err) } @@ -40,7 +49,8 @@ func main() { } } -func parseFlags(stlFilePath *string) { - flag.StringVar(stlFilePath, "file", "myfile.stl", "path to the binary STL file") +func (args *cliArgs) read() { + flag.BoolVar(&args.debugOutput, "debug", false, "enable to print log output") flag.Parse() + args.filePath = flag.Arg(0) } -- cgit v1.2.3-70-g09d2