Merge pull request #20246 from Homebrew/alias-symlink-names
aliases/aliases: fix naming of symlinks
This commit is contained in:
		
						commit
						b631179579
					
				@ -29,36 +29,36 @@ module Homebrew
 | 
			
		||||
      Alias.new(name).remove
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    sig { params(only: T::Array[String], block: T.proc.params(target: String, cmd: String).void).void }
 | 
			
		||||
    sig { params(only: T::Array[String], block: T.proc.params(name: String, command: String).void).void }
 | 
			
		||||
    def self.each(only, &block)
 | 
			
		||||
      Dir["#{HOMEBREW_ALIASES}/*"].each do |path|
 | 
			
		||||
        next if path.end_with? "~" # skip Emacs-like backup files
 | 
			
		||||
        next if File.directory?(path)
 | 
			
		||||
 | 
			
		||||
        _shebang, _meta, *lines = File.readlines(path)
 | 
			
		||||
        target = File.basename(path)
 | 
			
		||||
        next if !only.empty? && only.exclude?(target)
 | 
			
		||||
        _shebang, meta, *lines = File.readlines(path)
 | 
			
		||||
        name = T.must(meta)[/alias: brew (\S+)/, 1] || File.basename(path)
 | 
			
		||||
        next if !only.empty? && only.exclude?(name)
 | 
			
		||||
 | 
			
		||||
        lines.reject! { |line| line.start_with?("#") || line =~ /^\s*$/ }
 | 
			
		||||
        first_line = T.must(lines.first)
 | 
			
		||||
        cmd = first_line.chomp
 | 
			
		||||
        cmd.sub!(/ \$\*$/, "")
 | 
			
		||||
        command = first_line.chomp
 | 
			
		||||
        command.sub!(/ \$\*$/, "")
 | 
			
		||||
 | 
			
		||||
        if cmd.start_with? "brew "
 | 
			
		||||
          cmd.sub!(/^brew /, "")
 | 
			
		||||
        if command.start_with? "brew "
 | 
			
		||||
          command.sub!(/^brew /, "")
 | 
			
		||||
        else
 | 
			
		||||
          cmd = "!#{cmd}"
 | 
			
		||||
          command = "!#{command}"
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        yield target, cmd if block.present?
 | 
			
		||||
        yield name, command if block.present?
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    sig { params(aliases: String).void }
 | 
			
		||||
    def self.show(*aliases)
 | 
			
		||||
      each([*aliases]) do |target, cmd|
 | 
			
		||||
        puts "brew alias #{target}='#{cmd}'"
 | 
			
		||||
        existing_alias = Alias.new(target, cmd)
 | 
			
		||||
      each([*aliases]) do |name, command|
 | 
			
		||||
        puts "brew alias #{name}='#{command}'"
 | 
			
		||||
        existing_alias = Alias.new(name, command)
 | 
			
		||||
        existing_alias.link unless existing_alias.symlink.exist?
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -1,6 +0,0 @@
 | 
			
		||||
#! /bin/bash
 | 
			
		||||
# alias: brew foo
 | 
			
		||||
#:  * `foo` [args...]
 | 
			
		||||
#:    `brew foo` is an alias for `brew bar`
 | 
			
		||||
brew bar $*
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								Library/Homebrew/test/.brew-aliases/foo_test
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								Library/Homebrew/test/.brew-aliases/foo_test
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
#! /bin/bash
 | 
			
		||||
# alias: brew foo-test
 | 
			
		||||
#:  * `foo-test` [args...]
 | 
			
		||||
#:    `brew foo-test` is an alias for `brew bar`
 | 
			
		||||
brew bar $*
 | 
			
		||||
 | 
			
		||||
@ -7,12 +7,12 @@ RSpec.describe Homebrew::Cmd::Alias do
 | 
			
		||||
  it_behaves_like "parseable arguments"
 | 
			
		||||
 | 
			
		||||
  it "sets an alias", :integration_test do
 | 
			
		||||
    expect { brew "alias", "foo=bar" }
 | 
			
		||||
    expect { brew "alias", "foo-test=bar" }
 | 
			
		||||
      .to not_to_output.to_stdout
 | 
			
		||||
      .and not_to_output.to_stderr
 | 
			
		||||
      .and be_a_success
 | 
			
		||||
    expect { brew "alias" }
 | 
			
		||||
      .to output(/brew alias foo='bar'/).to_stdout
 | 
			
		||||
      .to output(/brew alias foo-test='bar'/).to_stdout
 | 
			
		||||
      .and not_to_output.to_stderr
 | 
			
		||||
      .and be_a_success
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user