Skip to content

Commit

Permalink
versions: enable '--compact' output
Browse files Browse the repository at this point in the history
This will be useful for shell tab completion when something like `brew
install <formula> --version <version>` is implemented.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information
jacknagel committed Jan 6, 2012
1 parent 49bb7b6 commit b26e66f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Library/Contributions/brew_bash_completion.sh
Expand Up @@ -197,6 +197,11 @@ _brew_to_completion()
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return
;;
versions)
local opts=$([[ "${COMP_WORDS[*]}" =~ "--compact" ]] || echo "--compact")
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return
;;
esac
fi

Expand Down
5 changes: 4 additions & 1 deletion Library/Contributions/manpages/brew.1.md
Expand Up @@ -272,10 +272,13 @@ For the full command list, see the COMMANDS section.

If `--installed` is passed, only list installed formulae.

* `versions` <formulae>:
* `versions [--compact]` <formulae>:
List previous versions of <formulae>, along with a command to checkout
each version.

If `--compact` is passed, show all options on a single line separated by
spaces.

* `--cache`:
Display Homebrew's download cache. *Default:* `~/Library/Caches/Homebrew`

Expand Down
28 changes: 14 additions & 14 deletions Library/Homebrew/cmd/versions.rb
Expand Up @@ -5,11 +5,15 @@ def versions
raise "Please `brew install git` first" unless system "/usr/bin/which -s git"

ARGV.formulae.all? do |f|
f.versions do |version, sha|
print Tty.white
print "#{version.ljust(8)} "
print Tty.reset
puts "git checkout #{sha} #{f.pretty_relative_path}"
if ARGV.include? '--compact'
puts f.versions * " "
else
f.versions do |version, sha|
print Tty.white
print "#{version.ljust(8)} "
print Tty.reset
puts "git checkout #{sha} #{f.pretty_relative_path}"
end
end
end
end
Expand Down Expand Up @@ -55,14 +59,10 @@ def sha_for_version version
end

def version_for_sha sha
begin
version = mktemp do
path = Pathname.new(Pathname.pwd+"#{name}.rb")
path.write text_from_sha(sha)
Formula.factory(path).version
end
rescue
opoo "Version of #{name} could not be determined for #{sha}."
end
mktemp do
path = Pathname.new(Pathname.pwd+"#{name}.rb")
path.write text_from_sha(sha)
Formula.factory(path).version
end rescue nil
end
end
7 changes: 5 additions & 2 deletions share/man/man1/brew.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "BREW" "1" "December 2011" "Homebrew" "brew"
.TH "BREW" "1" "January 2012" "Homebrew" "brew"
.
.SH "NAME"
\fBbrew\fR \- The missing package manager for OS X
Expand Down Expand Up @@ -304,9 +304,12 @@ Show the formulas that specify \fIformula\fR as a dependency\. The list is not r
If \fB\-\-installed\fR is passed, only list installed formulae\.
.
.TP
\fBversions\fR \fIformulae\fR
\fBversions [\-\-compact]\fR \fIformulae\fR
List previous versions of \fIformulae\fR, along with a command to checkout each version\.
.
.IP
If \fB\-\-compact\fR is passed, show all options on a single line separated by spaces\.
.
.TP
\fB\-\-cache\fR
Display Homebrew\'s download cache\. \fIDefault:\fR \fB~/Library/Caches/Homebrew\fR
Expand Down

0 comments on commit b26e66f

Please sign in to comment.