Guard suggestion capability (+ dependency) with build tag

This commit is contained in:
Dan Buch 2022-05-07 15:21:00 -04:00
parent 63b1a7deee
commit 974f2d410d
Signed by: meatballhat
GPG Key ID: A12F782281063434
11 changed files with 51 additions and 15 deletions

View File

@ -37,9 +37,15 @@ jobs:
- name: vet
run: go run internal/build/build.go vet
- name: test with tags
- name: test with urfave_cli_core tag
run: go run internal/build/build.go -tags urfave_cli_core test
- name: test with urfave_cli_no_docs tag
run: go run internal/build/build.go -tags urfave_cli_no_docs test
- name: test with urfave_cli_no_suggest tag
run: go run internal/build/build.go -tags urfave_cli_no_suggest test
- name: test
run: go run internal/build/build.go test
@ -47,7 +53,7 @@ jobs:
run: go run internal/build/build.go check-binary-size
- name: check-binary-size with tags (informational only)
run: go run internal/build/build.go -tags urfave_cli_no_docs check-binary-size || true
run: go run internal/build/build.go -tags urfave_cli_core check-binary-size
- name: Upload coverage to Codecov
if: success() && matrix.go == '1.18.x' && matrix.os == 'ubuntu-latest'

View File

@ -17,11 +17,11 @@ all: generate vet tag-test test check-binary-size tag-check-binary-size gfmrun t
.PHONY: tag-test
tag-test:
go run internal/build/build.go -tags urfave_cli_no_docs test
go run internal/build/build.go -tags urfave_cli_core test
.PHONY: tag-check-binary-size
tag-check-binary-size:
go run internal/build/build.go -tags urfave_cli_no_docs check-binary-size
go run internal/build/build.go -tags urfave_cli_core check-binary-size
.PHONY: gfmrun
gfmrun:

View File

@ -59,11 +59,21 @@ import (
You can use the following build tags:
#### `urfave_cli_core`
When set, applies all `urfave_cli_no.+` build tags to minimize resulting binary
size.
#### `urfave_cli_no_docs`
When set, this removes `ToMarkdown` and `ToMan` methods, so your application
won't be able to call those. This reduces the resulting binary size by about
300-400 KB (measured using Go 1.18.1 on Linux/amd64), due to less dependencies.
300-400 KB (measured using Go 1.18.1 on Linux/amd64), due to fewer dependencies.
#### `urfave_cli_no_suggest`
When set, the capability enabled by setting `App.Suggest` will be a no-op. This
reduces the resulting binary size due to fewer dependencies.
### GOPATH

View File

@ -1,5 +1,5 @@
//go:build !urfave_cli_no_docs
// +build !urfave_cli_no_docs
//go:build !urfave_cli_no_docs && !urfave_cli_core
// +build !urfave_cli_no_docs,!urfave_cli_core
package cli

View File

@ -1,5 +1,5 @@
//go:build !urfave_cli_no_docs
// +build !urfave_cli_no_docs
//go:build !urfave_cli_no_docs && !urfave_cli_core
// +build !urfave_cli_no_docs,!urfave_cli_core
package cli

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/BurntSushi/toml v1.1.0
github.com/antzucaro/matchr v0.0.0-20180616170659-cbc221335f3c
github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0
github.com/cpuguy83/go-md2man/v2 v2.0.1
golang.org/x/text v0.3.7
gopkg.in/yaml.v2 v2.4.0

10
go.sum
View File

@ -2,14 +2,16 @@ github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/antzucaro/matchr v0.0.0-20180616170659-cbc221335f3c h1:CucViv7orgFBMkehuFFdkCVF5ERovbkRRyhvaYaHu/k=
github.com/antzucaro/matchr v0.0.0-20180616170659-cbc221335f3c/go.mod h1:bV/CkX4+ANGDaBwbHkt9kK287al/i9BsB18PRBvyqYo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0 h1:R/qAiUxFT3mNgQaNqJe0IVznjKRNm23ohAIh9lgtlzc=
github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0/go.mod h1:v3ZDlfVAL1OrkKHbGSFFK60k0/7hruHPDq2XMs9Gu6U=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=

View File

@ -242,7 +242,7 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) {
tags := c.String("tags")
if strings.Contains(tags, "urfave_cli_no_docs") {
if strings.Contains(tags, "urfave_cli_core") || strings.Contains(tags, "urfave_cli_no_docs") {
desiredMinBinarySize = 1.39
}

View File

@ -1,3 +1,6 @@
//go:build !urfave_cli_no_suggest && !urfave_cli_core
// +build !urfave_cli_no_suggest,!urfave_cli_core
package cli
import (

12
suggestions_stubs.go Normal file
View File

@ -0,0 +1,12 @@
//go:build urfave_cli_no_suggest || urfave_cli_core
// +build urfave_cli_no_suggest urfave_cli_core
package cli
func (a *App) suggestFlagFromError(err error, _ string) (string, error) {
return "", err
}
func suggestCommand([]*Command, string) string {
return ""
}

View File

@ -1,3 +1,6 @@
//go:build !urfave_cli_no_suggest && !urfave_cli_core
// +build !urfave_cli_no_suggest,!urfave_cli_core
package cli
import (