Port Homebrew::Cmd::Log
This commit is contained in:
parent
bd1155be8f
commit
59adde2069
@ -1,12 +1,15 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cli/parser"
|
require "abstract_command"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
sig { returns(CLI::Parser) }
|
module Cmd
|
||||||
def self.log_args
|
class Log < AbstractCommand
|
||||||
Homebrew::CLI::Parser.new do
|
include FileUtils
|
||||||
|
|
||||||
|
cmd_args do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Show the `git log` for <formula> or <cask>, or show the log for the Homebrew repository
|
Show the `git log` for <formula> or <cask>, or show the log for the Homebrew repository
|
||||||
if no formula or cask is provided.
|
if no formula or cask is provided.
|
||||||
@ -31,11 +34,9 @@ module Homebrew
|
|||||||
|
|
||||||
named_args [:formula, :cask], max: 1, without_api: true
|
named_args [:formula, :cask], max: 1, without_api: true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.log
|
|
||||||
args = log_args.parse
|
|
||||||
|
|
||||||
|
sig { override.void }
|
||||||
|
def run
|
||||||
# As this command is simplifying user-run commands then let's just use a
|
# As this command is simplifying user-run commands then let's just use a
|
||||||
# user path, too.
|
# user path, too.
|
||||||
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
|
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
|
||||||
@ -45,11 +46,13 @@ module Homebrew
|
|||||||
else
|
else
|
||||||
path = args.named.to_paths.first
|
path = args.named.to_paths.first
|
||||||
tap = Tap.from_path(path)
|
tap = Tap.from_path(path)
|
||||||
git_log path.dirname, path, tap, args:
|
git_log T.must(path).dirname, path, tap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.git_log(cd_dir, path = nil, tap = nil, args:)
|
private
|
||||||
|
|
||||||
|
def git_log(cd_dir, path = nil, tap = nil)
|
||||||
cd cd_dir do
|
cd cd_dir do
|
||||||
repo = Utils.popen_read("git", "rev-parse", "--show-toplevel").chomp
|
repo = Utils.popen_read("git", "rev-parse", "--show-toplevel").chomp
|
||||||
if tap
|
if tap
|
||||||
@ -80,4 +83,6 @@ module Homebrew
|
|||||||
system "git", "log", *git_args
|
system "git", "log", *git_args
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/log"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
RSpec.describe "brew log" do
|
RSpec.describe Homebrew::Cmd::Log do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "shows the Git log for a given Formula", :integration_test do
|
it "shows the Git log for a given Formula", :integration_test do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user