Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: urfave/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.8.0
Choose a base ref
...
head repository: urfave/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.8.1
Choose a head ref
  • 6 commits
  • 6 files changed
  • 2 contributors

Commits on May 23, 2022

  1. Run docs tests against current work tree

    by creating a temporary go workspace to be used by gfmrun via `TMPDIR`.
    meatballhat committed May 23, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    5edc1b9 View commit details
  2. Set absolute bash path

    and slightly revert assertion in docs test to ensure flag ordering
    meatballhat committed May 23, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    8f47e6d View commit details
  3. Merge pull request #1403 from urfave/gfmrun-current

    Run docs tests against current work tree
    meatballhat authored May 23, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    595cabc View commit details

Commits on May 24, 2022

  1. Remove GPL2 dependency introduced in v2.7.0

    This commit replaces github.com/antzucaro/matchr (GPL2, introduced in v2.7.0)
    with github.com/xrash/smetrics (MIT License).
    
    Fixes issue 1404
    
    Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
    AkihiroSuda committed May 24, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    AkihiroSuda Akihiro Suda
    Copy the full SHA
    a14bd76 View commit details
  2. CI: workaround for golang.org/x/tools error

    Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
    AkihiroSuda committed May 24, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    AkihiroSuda Akihiro Suda
    Copy the full SHA
    3e31c9b View commit details
  3. Merge pull request #1405 from AkihiroSuda/remove-gpl2-dependency

    Remove GPL2 dependency introduced in v2.7.0
    meatballhat authored May 24, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5ff4e2a View commit details
Showing with 62 additions and 18 deletions.
  1. +4 −0 .github/workflows/cli.yml
  2. +1 −1 docs/v2/manual.md
  3. +1 −1 go.mod
  4. +2 −10 go.sum
  5. +42 −3 internal/build/build.go
  6. +12 −3 suggestions.go
4 changes: 4 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -34,6 +34,10 @@ jobs:
if: matrix.go == '1.18.x' && matrix.os == 'ubuntu-latest'
run: test -z $(gofmt -l .)

# https://github.com/urfave/cli/pull/1405#issuecomment-1135458582
- name: workaround for golang.org/x/tools error
run: go mod download golang.org/x/tools

- name: vet
run: go run internal/build/build.go vet

2 changes: 1 addition & 1 deletion docs/v2/manual.md
Original file line number Diff line number Diff line change
@@ -363,7 +363,7 @@ For example this:

<!-- {
"args": ["&#45;&#45;help"],
"output": "add a task to the list\n.*complete a task on the list\n.*\n\n.*\n.*Load configuration from FILE\n.*Language for the greeting.*"
"output": ".*Load configuration from FILE\n.*\n.*Language for the greeting.*"
} -->
``` go
package main
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ go 1.18

require (
github.com/BurntSushi/toml v1.1.0
github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0
github.com/cpuguy83/go-md2man/v2 v2.0.1
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
golang.org/x/text v0.3.7
gopkg.in/yaml.v2 v2.4.0
)
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
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/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=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
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=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
45 changes: 42 additions & 3 deletions internal/build/build.go
Original file line number Diff line number Diff line change
@@ -179,8 +179,43 @@ func testCleanup(packages []string) error {
return os.WriteFile("coverage.txt", out.Bytes(), 0644)
}

func GfmrunActionFunc(c *cli.Context) error {
filename := c.Args().Get(0)
func GfmrunActionFunc(cCtx *cli.Context) error {
top := cCtx.Path("top")

bash, err := exec.LookPath("bash")
if err != nil {
return err
}

os.Setenv("SHELL", bash)

tmpDir, err := os.MkdirTemp("", "urfave-cli*")
if err != nil {
return err
}

wd, err := os.Getwd()
if err != nil {
return err
}

if err := os.Chdir(tmpDir); err != nil {
return err
}

fmt.Fprintf(cCtx.App.ErrWriter, "# ---> workspace/TMPDIR is %q\n", tmpDir)

if err := runCmd("go", "work", "init", top); err != nil {
return err
}

os.Setenv("TMPDIR", tmpDir)

if err := os.Chdir(wd); err != nil {
return err
}

filename := cCtx.Args().Get(0)
if filename == "" {
filename = "README.md"
}
@@ -209,7 +244,11 @@ func GfmrunActionFunc(c *cli.Context) error {
return err
}

return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", filename)
if err := runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", filename); err != nil {
return err
}

return os.RemoveAll(tmpDir)
}

// checkBinarySizeActionFunc checks the size of an example binary to ensure that we are keeping size down
15 changes: 12 additions & 3 deletions suggestions.go
Original file line number Diff line number Diff line change
@@ -3,9 +3,18 @@ package cli
import (
"fmt"

"github.com/antzucaro/matchr"
"github.com/xrash/smetrics"
)

func jaroWinkler(a, b string) float64 {
// magic values are from https://github.com/xrash/smetrics/blob/039620a656736e6ad994090895784a7af15e0b80/jaro-winkler.go#L8
const (
boostThreshold = 0.7
prefixSize = 4
)
return smetrics.JaroWinkler(a, b, boostThreshold, prefixSize)
}

func suggestFlag(flags []Flag, provided string, hideHelp bool) string {
distance := 0.0
suggestion := ""
@@ -16,7 +25,7 @@ func suggestFlag(flags []Flag, provided string, hideHelp bool) string {
flagNames = append(flagNames, HelpFlag.Names()...)
}
for _, name := range flagNames {
newDistance := matchr.JaroWinkler(name, provided, true)
newDistance := jaroWinkler(name, provided)
if newDistance > distance {
distance = newDistance
suggestion = name
@@ -39,7 +48,7 @@ func suggestCommand(commands []*Command, provided string) (suggestion string) {
distance := 0.0
for _, command := range commands {
for _, name := range append(command.Names(), helpName, helpAlias) {
newDistance := matchr.JaroWinkler(name, provided, true)
newDistance := jaroWinkler(name, provided)
if newDistance > distance {
distance = newDistance
suggestion = name