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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cli/parser"
|
require "abstract_command"
|
||||||
require "formula"
|
require "formula"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module Cmd
|
||||||
|
class NodenvSync < AbstractCommand
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def nodenv_sync_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Create symlinks for Homebrew's installed NodeJS versions in `~/.nodenv/versions`.
|
Create symlinks for Homebrew's installed NodeJS versions in `~/.nodenv/versions`.
|
||||||
|
|
||||||
@ -19,10 +17,9 @@ module Homebrew
|
|||||||
|
|
||||||
named_args :none
|
named_args :none
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
sig { override.void }
|
||||||
def nodenv_sync
|
def run
|
||||||
nodenv_root = Pathname(ENV.fetch("HOMEBREW_NODENV_ROOT", Pathname(Dir.home)/".nodenv"))
|
nodenv_root = Pathname(ENV.fetch("HOMEBREW_NODENV_ROOT", Pathname(Dir.home)/".nodenv"))
|
||||||
|
|
||||||
# Don't run multiple times at once.
|
# Don't run multiple times at once.
|
||||||
@ -34,8 +31,6 @@ module Homebrew
|
|||||||
nodenv_versions.mkpath
|
nodenv_versions.mkpath
|
||||||
FileUtils.touch nodenv_sync_running
|
FileUtils.touch nodenv_sync_running
|
||||||
|
|
||||||
nodenv_sync_args.parse
|
|
||||||
|
|
||||||
HOMEBREW_CELLAR.glob("node{,@*}")
|
HOMEBREW_CELLAR.glob("node{,@*}")
|
||||||
.flat_map(&:children)
|
.flat_map(&:children)
|
||||||
.each { |path| link_nodenv_versions(path, nodenv_versions) }
|
.each { |path| link_nodenv_versions(path, nodenv_versions) }
|
||||||
@ -49,6 +44,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
sig { params(path: Pathname, nodenv_versions: Pathname).void }
|
sig { params(path: Pathname, nodenv_versions: Pathname).void }
|
||||||
def link_nodenv_versions(path, nodenv_versions)
|
def link_nodenv_versions(path, nodenv_versions)
|
||||||
nodenv_versions.mkpath
|
nodenv_versions.mkpath
|
||||||
@ -67,4 +64,6 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
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