Created
June 28, 2023 12:54
-
-
Save ryansch/ab8d46b87d6e34b2cc3da8a036fa4a39 to your computer and use it in GitHub Desktop.
ThorHelp (doesn't work with required options)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ThorHelp | |
# This adds a --help option to all Thor commands. | |
def self.included(base) | |
base.class_eval do | |
class_option :help, | |
type: :boolean, | |
aliases: ["-h"], | |
desc: "Describe command" | |
class_before :check_help | |
no_commands do | |
def check_help | |
if options[:help] | |
help(@_invocations[self.class].first) | |
exit | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment