diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fc51337..d0ad1de 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,6 +14,12 @@ updates: - "andyone" reviewers: - "andyone" + groups: + all: + applies-to: version-updates + update-types: + - "minor" + - "patch" - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/images/card.svg b/.github/images/card.svg new file mode 100644 index 0000000..cca9c22 --- /dev/null +++ b/.github/images/card.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.github/images/license.svg b/.github/images/license.svg new file mode 100644 index 0000000..8990e77 --- /dev/null +++ b/.github/images/license.svg @@ -0,0 +1 @@ +license: Apache-2.0licenseApache-2.0 \ No newline at end of file diff --git a/.github/images/usage.svg b/.github/images/usage.svg new file mode 100644 index 0000000..e91e279 --- /dev/null +++ b/.github/images/usage.svg @@ -0,0 +1,74 @@ + + + + MDToc Usage + + + + + + + + + + + + + + + + + + + Terminal + + Usage: mdtoc {options} file + Options + --flat, -f ........... Print flat (horizontal) ToC + --html, -H ........... Render HTML ToC instead Markdown (works with --flat) + --min-level, -m 1-6 .. Minimal header level + --max-level, -M 1-6 .. Maximum header level + --no-color, -nc ...... Disable colors in output + --help, -h ........... Show this help message + --version, -v ........ Show version + Examples + mdtoc readme.md + Generate table of contents for readme.md + mdtoc -m 2 -M 4 readme.md + Generate table of contents for readme.md with 2-4 level headers + + + diff --git a/Makefile b/Makefile index 87011c8..f80c085 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,40 @@ ################################################################################ -# This Makefile generated by GoMakeGen 2.3.0 using next command: +# This Makefile generated by GoMakeGen 3.0.2 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen ################################################################################ -export GO111MODULE=on - ifdef VERBOSE ## Print verbose information (Flag) VERBOSE_FLAG = -v endif -COMPAT ?= 1.18 +COMPAT ?= 1.19 MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) ################################################################################ .DEFAULT_GOAL := help -.PHONY = fmt vet all clean deps update init vendor mod-init mod-update mod-download mod-vendor help +.PHONY = fmt vet all install uninstall clean deps update init vendor mod-init mod-update mod-download mod-vendor help ################################################################################ all: mdtoc ## Build all binaries mdtoc: - go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" mdtoc.go + @echo "Building mdtoc…" + @go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" mdtoc.go install: ## Install all binaries - cp mdtoc /usr/bin/mdtoc + @echo "Installing binaries…" + @cp mdtoc /usr/bin/mdtoc uninstall: ## Uninstall all binaries - rm -f /usr/bin/mdtoc + @echo "Removing installed binaries…" + @rm -f /usr/bin/mdtoc init: mod-init ## Initialize new module @@ -44,57 +45,70 @@ update: mod-update ## Update dependencies to the latest versions vendor: mod-vendor ## Make vendored copy of dependencies mod-init: + @echo "[1/2] Modules initialization…" ifdef MODULE_PATH ## Module path for initialization (String) - go mod init $(MODULE_PATH) + @go mod init $(MODULE_PATH) else - go mod init + @go mod init endif + @echo "[2/2] Dependencies cleanup…" ifdef COMPAT ## Compatible Go version (String) - go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) else - go mod tidy $(VERBOSE_FLAG) + @go mod tidy $(VERBOSE_FLAG) endif mod-update: + @echo "[1/4] Updating dependencies…" ifdef UPDATE_ALL ## Update all dependencies (Flag) - go get -u $(VERBOSE_FLAG) all + @go get -u $(VERBOSE_FLAG) all else - go get -u $(VERBOSE_FLAG) ./... + @go get -u $(VERBOSE_FLAG) ./... endif + @echo "[2/4] Stripping toolchain info…" + @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || : + + @echo "[3/4] Dependencies cleanup…" ifdef COMPAT - go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) else - go mod tidy $(VERBOSE_FLAG) + @go mod tidy $(VERBOSE_FLAG) endif - test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : + @echo "[4/4] Updating vendored dependencies…" + @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : mod-download: - go mod download + @echo "Downloading dependencies…" + @go mod download mod-vendor: - rm -rf vendor && go mod vendor $(VERBOSE_FLAG) + @echo "Vendoring dependencies…" + @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : fmt: ## Format source code with gofmt - find . -name "*.go" -exec gofmt -s -w {} \; + @echo "Formatting sources…" + @find . -name "*.go" -exec gofmt -s -w {} \; vet: ## Runs 'go vet' over sources - go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... + @echo "Running 'go vet' over sources…" + @go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... clean: ## Remove generated files - rm -f mdtoc + @echo "Removing built binaries…" + @rm -f mdtoc help: ## Show this info @echo -e '\n\033[1mTargets:\033[0m\n' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-9s\033[0m %s\n", $$1, $$2}' @echo -e '\n\033[1mVariables:\033[0m\n' @grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \ | sed 's/ifdef //' \ - | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 2.3.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 3.0.2\033[0m\n' ################################################################################ diff --git a/README.md b/README.md index 753866c..7b664ad 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ -

+

GitHub Actions CI Status GitHub Actions CodeQL Status - GoReportCard Codebeat badge - +

-

Installation • Usage • Build Status • Contributing • License

+

Installation • Usage • CI Status • Contributing • License


@@ -18,10 +17,10 @@ #### From source -To build the MDToc from scratch, make sure you have a working Go 1.18+ workspace ([instructions](https://go.dev/doc/install)), then: +To build the MDToc from scratch, make sure you have a working Go 1.21+ workspace ([instructions](https://go.dev/doc/install)), then: ``` -go install github.com/essentialkaos/mdtoc +go install github.com/essentialkaos/mdtoc@latest ``` #### Prebuilt binaries @@ -34,30 +33,9 @@ bash <(curl -fsSL https://apps.kaos.st/get) mdtoc ### Usage -``` -Usage: mdtoc {options} file - -Options - - --flat, -f Print flat (horizontal) ToC - --html, -H Render HTML ToC instead Markdown (works with --flat) - --min-level, -m 1-6 Minimal header level - --max-level, -M 1-6 Maximum header level - --no-color, -nc Disable colors in output - --help, -h Show this help message - --version, -v Show version - -Examples - - mdtoc readme.md - Generate table of contents for readme.md - - mdtoc -m 2 -M 4 readme.md - Generate table of contents for readme.md with 2-4 level headers - -``` + -### Build Status +### CI Status | Branch | Status | |------------|--------| diff --git a/cli/cli.go b/cli/cli.go index ae29a94..68f3385 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -22,6 +22,7 @@ import ( "github.com/essentialkaos/ek/v12/strutil" "github.com/essentialkaos/ek/v12/support" "github.com/essentialkaos/ek/v12/support/deps" + "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/usage" "github.com/essentialkaos/ek/v12/usage/completion/bash" @@ -36,7 +37,7 @@ import ( // App info const ( APP = "MDToc" - VER = "1.2.6" + VER = "1.2.7" DESC = "Utility for generating table of contents for markdown files" ) @@ -91,11 +92,9 @@ func Init(gitRev string, gomod []byte) { args, errs := options.Parse(optMap) - if len(errs) != 0 { - for _, err := range errs { - printError(err.Error()) - } - + if !errs.IsEmpty() { + terminal.Error("Options parsing errors:") + terminal.Error(errs.String()) os.Exit(1) } @@ -176,7 +175,7 @@ func process(file string) { headers := extractHeaders(file) if len(headers) == 0 { - printWarn("Headers not found in given file") + terminal.Warn("Headers not found in given file") return } @@ -225,7 +224,7 @@ func printTOC(headers []*Header) { } if toc == "" { - printWarn("Suitable headers not found in given file") + terminal.Warn("Suitable headers not found in given file") return } @@ -373,19 +372,9 @@ func removeBadges(text string) string { return badgeRegExp.ReplaceAllString(text, "") } -// printError prints error message to console -func printError(f string, a ...interface{}) { - fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...) -} - -// printError prints warning message to console -func printWarn(f string, a ...interface{}) { - fmtc.Fprintf(os.Stderr, "{y}"+f+"{!}\n", a...) -} - // printErrorAndExit prints error message and exit with exit code 1 func printErrorAndExit(f string, a ...interface{}) { - printError(f, a...) + terminal.Error(f, a...) os.Exit(1) } diff --git a/go.mod b/go.mod index 0be64d3..0bf7393 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/essentialkaos/mdtoc go 1.18 -require github.com/essentialkaos/ek/v12 v12.113.1 +require github.com/essentialkaos/ek/v12 v12.127.0 require ( - github.com/essentialkaos/depsy v1.1.0 // indirect - golang.org/x/sys v0.18.0 // indirect + github.com/essentialkaos/depsy v1.3.0 // indirect + golang.org/x/sys v0.21.0 // indirect ) diff --git a/go.sum b/go.sum index efceef3..07ba145 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= -github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= -github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg= -github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U= +github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= +github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= +github.com/essentialkaos/ek/v12 v12.127.0 h1:fU5A+QbIZ7NTq1K5jGVwAWwuLtBUhsIKuRWYT78hE+Q= +github.com/essentialkaos/ek/v12 v12.127.0/go.mod h1:71IJ7m82hgjrvWnhL+z0vIhguxz47/rfVma5/CeI5Fw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=