summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-05-27 10:51:44 +0200
committerxengineering <mail2xengineering@protonmail.com>2021-05-27 10:55:19 +0200
commit4d9bd20ea82d483923b8f2d4e59500b378d224c9 (patch)
tree6a535dbc6d6b1cf5d6736d4cc97238d983d16264
parent5bf517d5692541dfa1f4fc506c51e0fb7b8a76b4 (diff)
downloadstlscope-4d9bd20ea82d483923b8f2d4e59500b378d224c9.tar
stlscope-4d9bd20ea82d483923b8f2d4e59500b378d224c9.tar.zst
stlscope-4d9bd20ea82d483923b8f2d4e59500b378d224c9.zip
Update CLI Interface0.2.0
-rw-r--r--Makefile4
-rw-r--r--README.md6
-rw-r--r--main.go22
3 files changed, 22 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 9bcf23e..de52702 100644
--- a/Makefile
+++ b/Makefile
@@ -10,11 +10,11 @@ clean:
rm -rf build
debug:
- go run ./... -file data/L.stl
+ go run ./... data/L.stl
install: all
mkdir -p $(PREFIX)/bin
install -m 755 build/stlscope $(PREFIX)/bin
-.PHONY: all clean debug install release
+.PHONY: all clean debug install
diff --git a/README.md b/README.md
index e03d7ca..a7d293c 100644
--- a/README.md
+++ b/README.md
@@ -7,12 +7,14 @@ This little program will allow you to view STL files from your terminal. It uses
## Usage
-Please use the help page to view current usage:
+It could not be simpler:
```
-$ stlscope -h
+$ stlscope myfile.stl
```
+Have a look at `stlscope -h` to learn about further options.
+
## Development Milestones
Done (most recent first):
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)
}