rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.14k stars 553 forks source link

Return subcommand if its already registered #883

Open bradgessler opened 3 months ago

bradgessler commented 3 months ago

When running Thor in a development environment on a server a code reloader, I noticed the subcommand would register duplicates like this:

tinyzap/server [cli-puma] → bin/tinyzap
Commands:
  tinyzap echo                                                          # Echos the input from stdin
  tinyzap help [COMMAND]                                                # Describe available commands or one specific command
  tinyzap links                                                         # Manage links
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links list                                                    # Lists links
  tinyzap links list                                                    # Lists links
  tinyzap links list                                                    # Lists links
  tinyzap links list                                                    # Lists links
  tinyzap links list                                                    # Lists links
  tinyzap links list                                                    # Lists links
  tinyzap links list                                                    # Lists links
  tinyzap login                                                         # Login to TinyZap
  tinyzap whoami                                                        # Prints your current login information

tinyzap/server [cli-puma] →

This PR fixes that problem by checking to see if the command is registered already. If it is, it returns the existing subcommand.

tinyzap/server [cli-puma] → bin/tinyzap
Commands:
  tinyzap echo                                                          # Echos the input from stdin
  tinyzap help [COMMAND]                                                # Describe available commands or one specific command
  tinyzap links                                                         # Manage links
  tinyzap links create -d, --description=DESCRIPTION -t, --title=TITLE  # Create a new link
  tinyzap links help [COMMAND]                                          # Describe subcommands or one specific subcommand
  tinyzap links list                                                    # Lists links
  tinyzap login                                                         # Login to TinyZap
  tinyzap whoami                                                        # Prints your current login information