rails / thor

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

The namespaces don't work as documented #792

Open timuckun opened 2 years ago

timuckun commented 2 years ago

See the following gist https://gist.github.com/timuckun/4b1e8f860cd47e0dc27423cad9563f4d

Calling this file results in this output (notice the lack of namespaces)

 ./do
Commands:
  do dump            # dumps the database using pgdump
  do help [COMMAND]  # Describe available commands or one specific command
  do restore         # loads the database from pgdump

Commands:
  do help [COMMAND]  # Describe available commands or one specific command
  do start           # starts docker compose
apurvis commented 1 year ago

+1

timuckun commented 1 year ago

Is anybody even looking at these tickets?

p8 commented 11 months ago

Renaming the file to Thorfile and removing the calls to start does show the namespace when running thor list

require 'thor'
require 'dotenv'
Dotenv.load

module Db
  class Ops < Thor
    namespace :db
    def self.exit_on_failure?
      true
    end

    desc 'dump', 'dumps the database using pgdump'
    def backup
      puts 'Backup'
    end
    desc 'restore', 'loads the database from pgdump'
    def restore
      puts 'restore'
    end
  end
end

module Docker
  class Commands < Thor
    namespace :docker
    desc 'start', 'starts docker compose'
    def start; end
  end
end

Outputs:

db
--
thor db:dump     # dumps the database using pgdump
thor db:restore  # loads the database from pgdump

docker
------
thor docker:start  # starts docker compose

I'm not sure what the expected behaviour is for the original example file. Is this something Thor should support?

p8 commented 11 months ago

Hmm, this also how the https://github.com/rails/thor/blob/5fb6206a6d2d7bfb40bcb851c2e118ba39f69757/spec/fixtures/help.thor is implemented so I guess this is a bug.