Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a default Help command #31

Closed
thegedge opened this issue May 29, 2018 · 4 comments
Closed

Add a default Help command #31

thegedge opened this issue May 29, 2018 · 4 comments

Comments

@thegedge
Copy link
Contributor

Pretty much every command-line tool needs help, so perhaps we could provide a template command that can be incorporated into projects and provide a sane default set of help. My experience is that CLI tools often have both short-form and long-form descriptions.

The short-form description gets used generally when showing commands in a list (e.g., mytool help showing all commands and a short description). The long-form will be shown in help for just that command (e.g., mytool help mycommand).

Here's an incredibly rough sketch:

module CLI
  module Kit
    class Help < CLI::Kit::BaseCommand
      def call(args, _command_name)
        if args.empty?
          all_commands.each { |_command_name, command| puts CLI::UI.fmt(command.short_description) }
        else
          command = all_commands.find { |command_name, _command| command_name == args.first }
          puts CLI::UI.fmt(command.long_description) if command
          # else error message for unknown command
        end
      end

      # The subclassed help command will provide the list of all commands
      def all_commands
        raise NotImplementedError
      end
    end
  end
end
@burke
Copy link
Member

burke commented May 29, 2018

Yeah, I would love to provide some sort of help facility. I started extracting dev's at one point, but I don't actually like it enough to drag into cli-kit.

It's tough to find a good paradigm for help when you rely on lazy-loading like we do.

@thegedge
Copy link
Contributor Author

It's tough to find a good paradigm for help when you rely on lazy-loading like we do.

Do you think help is perhaps where we don't mind taking the hit of loading up all of the code? Or do you think separating help for commands from the commands themselves would be a more effective approach?

@burke
Copy link
Member

burke commented May 30, 2018

I guess it's not a completely crazy idea to have dev help eager-load, as long as there aren't more common paths that trigger it. I wonder how long it would take, I don't think there's any path that eager-loads that much code right now.

@technicalpickles
Copy link

Looks like this happened at some point: https://github.com/Shopify/cli-kit/blob/master/gen/lib/gen/commands/help.rb

@lugray lugray closed this as completed Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants