urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
22.22k stars 1.7k forks source link

fix: check duplicated sub command name and alias #1805

Closed linrl3 closed 1 year ago

linrl3 commented 1 year ago

What type of PR is this?

What this PR does / why we need it:

Fix https://github.com/urfave/cli/issues/785.

Which issue(s) this PR fixes:

Fix https://github.com/urfave/cli/issues/785

Special notes for your reviewer:

This fix is only for v2. Do we need to fix it in other versions?

Testing

package main

import (
    "fmt"

    "github.com/urfave/cli/v2"
)

func main() {
    app := &cli.App{
        Name: "linrl3",
        Commands: []*cli.Command{
            {Name: "sub1"},
            {Name: "sub1"},
        },
    }
    if err := app.Run([]string{"linrl3", "sub1"}); err != nil {
        fmt.Println(err)
    }
}

result:

result:
➜  cli git:(fix/v2_duplicate_subcommand) ✗ go run cmd/dummyrun/main.go
parent command [linrl3] has duplicated subcommand name or alias: sub1

Release Notes

(REQUIRED)

- fix: if sub-commands in the same level have same name or alias, an error would return
abitrolly commented 1 year ago

On the surface LGTM. Need somebody to get into deeper logic, like using new error module for v2 branch.

linrl3 commented 1 year ago

On the surface LGTM. Need somebody to get into deeper logic, like using new error module for v2 branch.

@abitrolly Who do you think should review the code? Could you invite him/her?

linrl3 commented 1 year ago

@linrl3 Thank you so much for your PR.

@dearchap Thanks! What is the next step? Is there a routine merging and release?