From 16a2ada206b2c9548050ee14ca194aa3333a741f Mon Sep 17 00:00:00 2001 From: bjoernf Date: Sun, 12 May 2024 17:21:50 +0200 Subject: [PATCH] Apply Patch --- Makefile | 18 ++++++++++++------ main.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 1e961ce..bcd3457 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,17 @@ all: - go run main.go tree.go test_files/test.md + go build . + +run: + go run . test_files/test.md test: - go run main.go tree.go test_files/test.md - go run main.go tree.go test_files/README.md - go run main.go tree.go test_files/weird_headers.md - go run main.go tree.go test_files/audio.md + go run . test_files/test.md + go run . test_files/README.md + go run . test_files/weird_headers.md + go run . test_files/audio.md + +install: + cp -v mdtoc /usr/local/bin/. clean: - rm -vf main + go clean diff --git a/main.go b/main.go index a73faa0..a0b7063 100644 --- a/main.go +++ b/main.go @@ -61,8 +61,19 @@ func parse_file(file_name string) []heading { return headings } +func usage() { + fmt.Printf("Usage: mdtoc [FILE]\n") + os.Exit(1) +} + func main() { - file_name := os.Args[1] + var file_name string = "" + + if len(os.Args) == 2 { + file_name = os.Args[1] + } else { + usage() + } var headings []heading = nil