Merge pull request 'Apply Patch' (#1) from usage into master

Reviewed-on: #1
This commit is contained in:
bjoernf 2024-05-12 17:25:14 +02:00
commit 8cf41b0614
2 changed files with 24 additions and 7 deletions

View File

@ -1,11 +1,17 @@
all: all:
go run main.go tree.go test_files/test.md go build .
run:
go run . test_files/test.md
test: test:
go run main.go tree.go test_files/test.md go run . test_files/test.md
go run main.go tree.go test_files/README.md go run . test_files/README.md
go run main.go tree.go test_files/weird_headers.md go run . test_files/weird_headers.md
go run main.go tree.go test_files/audio.md go run . test_files/audio.md
install:
cp -v mdtoc /usr/local/bin/.
clean: clean:
rm -vf main go clean

13
main.go
View File

@ -61,8 +61,19 @@ func parse_file(file_name string) []heading {
return headings return headings
} }
func usage() {
fmt.Printf("Usage: mdtoc [FILE]\n")
os.Exit(1)
}
func main() { 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 var headings []heading = nil