Guard suggestion capability (+ dependency) with build tag
This commit is contained in:
parent
63b1a7deee
commit
974f2d410d
10
.github/workflows/cli.yml
vendored
10
.github/workflows/cli.yml
vendored
@ -37,9 +37,15 @@ jobs:
|
|||||||
- name: vet
|
- name: vet
|
||||||
run: go run internal/build/build.go 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
|
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
|
- name: test
|
||||||
run: go run internal/build/build.go test
|
run: go run internal/build/build.go test
|
||||||
|
|
||||||
@ -47,7 +53,7 @@ jobs:
|
|||||||
run: go run internal/build/build.go check-binary-size
|
run: go run internal/build/build.go check-binary-size
|
||||||
|
|
||||||
- name: check-binary-size with tags (informational only)
|
- 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
|
- name: Upload coverage to Codecov
|
||||||
if: success() && matrix.go == '1.18.x' && matrix.os == 'ubuntu-latest'
|
if: success() && matrix.go == '1.18.x' && matrix.os == 'ubuntu-latest'
|
||||||
|
4
Makefile
4
Makefile
@ -17,11 +17,11 @@ all: generate vet tag-test test check-binary-size tag-check-binary-size gfmrun t
|
|||||||
|
|
||||||
.PHONY: tag-test
|
.PHONY: tag-test
|
||||||
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
|
.PHONY: tag-check-binary-size
|
||||||
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
|
.PHONY: gfmrun
|
||||||
gfmrun:
|
gfmrun:
|
||||||
|
12
README.md
12
README.md
@ -59,11 +59,21 @@ import (
|
|||||||
|
|
||||||
You can use the following build tags:
|
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`
|
#### `urfave_cli_no_docs`
|
||||||
|
|
||||||
When set, this removes `ToMarkdown` and `ToMan` methods, so your application
|
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
|
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
|
### GOPATH
|
||||||
|
|
||||||
|
4
docs.go
4
docs.go
@ -1,5 +1,5 @@
|
|||||||
//go:build !urfave_cli_no_docs
|
//go:build !urfave_cli_no_docs && !urfave_cli_core
|
||||||
// +build !urfave_cli_no_docs
|
// +build !urfave_cli_no_docs,!urfave_cli_core
|
||||||
|
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//go:build !urfave_cli_no_docs
|
//go:build !urfave_cli_no_docs && !urfave_cli_core
|
||||||
// +build !urfave_cli_no_docs
|
// +build !urfave_cli_no_docs,!urfave_cli_core
|
||||||
|
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.1.0
|
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
|
github.com/cpuguy83/go-md2man/v2 v2.0.1
|
||||||
golang.org/x/text v0.3.7
|
golang.org/x/text v0.3.7
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
|
10
go.sum
10
go.sum
@ -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/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 h1:CucViv7orgFBMkehuFFdkCVF5ERovbkRRyhvaYaHu/k=
|
||||||
github.com/antzucaro/matchr v0.0.0-20180616170659-cbc221335f3c/go.mod h1:bV/CkX4+ANGDaBwbHkt9kK287al/i9BsB18PRBvyqYo=
|
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/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0 h1:R/qAiUxFT3mNgQaNqJe0IVznjKRNm23ohAIh9lgtlzc=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0/go.mod h1:v3ZDlfVAL1OrkKHbGSFFK60k0/7hruHPDq2XMs9Gu6U=
|
||||||
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/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
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/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 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
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 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
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=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
|
||||||
|
@ -242,7 +242,7 @@ func checkBinarySizeActionFunc(c *cli.Context) (err error) {
|
|||||||
|
|
||||||
tags := c.String("tags")
|
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
|
desiredMinBinarySize = 1.39
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//go:build !urfave_cli_no_suggest && !urfave_cli_core
|
||||||
|
// +build !urfave_cli_no_suggest,!urfave_cli_core
|
||||||
|
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
12
suggestions_stubs.go
Normal file
12
suggestions_stubs.go
Normal 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 ""
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
//go:build !urfave_cli_no_suggest && !urfave_cli_core
|
||||||
|
// +build !urfave_cli_no_suggest,!urfave_cli_core
|
||||||
|
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user