Port Homebrew::Cmd::PyenvSync
This commit is contained in:
parent
427b527335
commit
6c260db277
@ -1,15 +1,13 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def pyenv_sync_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module Cmd
|
||||
class PyenvSync < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Create symlinks for Homebrew's installed Python versions in `~/.pyenv/versions`.
|
||||
|
||||
@ -19,10 +17,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def pyenv_sync
|
||||
sig { override.void }
|
||||
def run
|
||||
pyenv_root = Pathname(ENV.fetch("HOMEBREW_PYENV_ROOT", Pathname(Dir.home)/".pyenv"))
|
||||
|
||||
# Don't run multiple times at once.
|
||||
@ -33,9 +30,6 @@ module Homebrew
|
||||
pyenv_versions = pyenv_root/"versions"
|
||||
pyenv_versions.mkpath
|
||||
FileUtils.touch pyenv_sync_running
|
||||
|
||||
pyenv_sync_args.parse
|
||||
|
||||
HOMEBREW_CELLAR.glob("python{,@*}")
|
||||
.flat_map(&:children)
|
||||
.each { |path| link_pyenv_versions(path, pyenv_versions) }
|
||||
@ -49,6 +43,8 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { params(path: Pathname, pyenv_versions: Pathname).void }
|
||||
def link_pyenv_versions(path, pyenv_versions)
|
||||
pyenv_versions.mkpath
|
||||
@ -66,3 +62,5 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
8
Library/Homebrew/test/cmd/pyenv-sync_spec.rb
Normal file
8
Library/Homebrew/test/cmd/pyenv-sync_spec.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/pyenv-sync"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe Homebrew::Cmd::PyenvSync do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user