help_spec: fix and generate help text in help.rb
This commit is contained in:
		
							parent
							
								
									38feaf1270
								
							
						
					
					
						commit
						b5b988cbb1
					
				@ -35,11 +35,8 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
      def post_initialize
 | 
			
		||||
        @parser.on_tail("-h", "--help", "Show this message") do
 | 
			
		||||
          puts @parser.to_s.sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ")
 | 
			
		||||
                      .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}")
 | 
			
		||||
                      .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
 | 
			
		||||
                      .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}")
 | 
			
		||||
          exit
 | 
			
		||||
          puts generate_help_text
 | 
			
		||||
          exit 0
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
@ -128,6 +125,13 @@ module Homebrew
 | 
			
		||||
        Homebrew::CLI::Parser.global_options.key?(name.to_sym)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def generate_help_text
 | 
			
		||||
        @parser.to_s.sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ")
 | 
			
		||||
               .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}")
 | 
			
		||||
               .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
 | 
			
		||||
               .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}")
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      private
 | 
			
		||||
 | 
			
		||||
      def enable_switch(*names)
 | 
			
		||||
 | 
			
		||||
@ -38,14 +38,6 @@ module Homebrew
 | 
			
		||||
    module_function
 | 
			
		||||
 | 
			
		||||
    def help(cmd = nil, flags = {})
 | 
			
		||||
      # Let OptionParser generate help text for commands which have a parser defined
 | 
			
		||||
      begin
 | 
			
		||||
        Homebrew.send("#{cmd.tr("-", "_")}_args".to_sym)
 | 
			
		||||
        return
 | 
			
		||||
      rescue NoMethodError
 | 
			
		||||
        nil
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      # Resolve command aliases and find file containing the implementation.
 | 
			
		||||
      if cmd
 | 
			
		||||
        cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
 | 
			
		||||
@ -83,6 +75,14 @@ module Homebrew
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def command_help(path)
 | 
			
		||||
      # Let OptionParser generate help text for commands which have a parser defined
 | 
			
		||||
      begin
 | 
			
		||||
        cmd = path.basename(path.extname)
 | 
			
		||||
        return Homebrew.send("#{cmd.to_s.tr("-", "_")}_args".to_sym).generate_help_text
 | 
			
		||||
      rescue NoMethodError
 | 
			
		||||
        nil
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      help_lines = command_help_lines(path)
 | 
			
		||||
      if help_lines.empty?
 | 
			
		||||
        opoo "No help text in: #{path}" if ARGV.homebrew_developer?
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ describe "brew", :integration_test do
 | 
			
		||||
 | 
			
		||||
    it "prints help for a documented Ruby developer command" do
 | 
			
		||||
      expect { brew "help", "update-test" }
 | 
			
		||||
        .to output(/^brew update-test/).to_stdout
 | 
			
		||||
        .to output(/^Usage: brew update-test/).to_stdout
 | 
			
		||||
        .and be_a_success
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user