Port Homebrew::Cmd::NodenvSync
This commit is contained in:
parent
a43224cb4a
commit
c5dfac1f2c
@ -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 nodenv_sync_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module Cmd
|
||||
class NodenvSync < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Create symlinks for Homebrew's installed NodeJS versions in `~/.nodenv/versions`.
|
||||
|
||||
@ -19,10 +17,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def nodenv_sync
|
||||
sig { override.void }
|
||||
def run
|
||||
nodenv_root = Pathname(ENV.fetch("HOMEBREW_NODENV_ROOT", Pathname(Dir.home)/".nodenv"))
|
||||
|
||||
# Don't run multiple times at once.
|
||||
@ -34,8 +31,6 @@ module Homebrew
|
||||
nodenv_versions.mkpath
|
||||
FileUtils.touch nodenv_sync_running
|
||||
|
||||
nodenv_sync_args.parse
|
||||
|
||||
HOMEBREW_CELLAR.glob("node{,@*}")
|
||||
.flat_map(&:children)
|
||||
.each { |path| link_nodenv_versions(path, nodenv_versions) }
|
||||
@ -49,6 +44,8 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { params(path: Pathname, nodenv_versions: Pathname).void }
|
||||
def link_nodenv_versions(path, nodenv_versions)
|
||||
nodenv_versions.mkpath
|
||||
@ -67,4 +64,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
8
Library/Homebrew/test/cmd/nodenv-sync_spec.rb
Normal file
8
Library/Homebrew/test/cmd/nodenv-sync_spec.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/nodenv-sync"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe Homebrew::Cmd::NodenvSync do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user