gofr-dev / gofr

An opinionated Go framework for accelerated microservice development
https://gofr.dev
Apache License 2.0
1.3k stars 133 forks source link

SubCommand Pattern Matching fails if a subcommand is prefix of another subcommand using cmd interface #686

Open KedarisettiSreeVamsi opened 4 weeks ago

KedarisettiSreeVamsi commented 4 weeks ago

Describe the bug Let's take an example where there are 2 subcommands available here I am taking it as 'h' and 'hello' where h refers to help command and hello for hello world response as in the provided examples.

To Reproduce Steps to reproduce the behavior, if applicable:

  1. The code is

      package main
    
      import "gofr.dev/pkg/gofr"
    
      func main(){
    
      app := gofr.NewCmd()
    
      app.SubCommand("h",func(c *gofr.Context) (interface{},error){
              return "help",nil
      })
    
      app.SubCommand("hello",func(c *gofr.Context) (interface{},error){
              return "Hello World!",nil
      })
    
      app.Run()
     }
  2. The issue is when we run

image

Expected behavior A clear and concise description of what you expected to happen.

It should actually attempt to run Hello World but ran h Subcommand providing the output as help.

Screenshots If applicable, add screenshots to help explain your problem.

Environments (please complete the following information):

More description Add any other context about the problem here.

KedarisettiSreeVamsi commented 4 weeks ago

Please assign this issue to me as I have already provided a fix to it via #675 .

KedarisettiSreeVamsi commented 3 weeks ago

@aryanmehrotra @srijan-27 @vipul-rawat can someone assign this issue to me.