Browse Source

fix clippy (#1126)

* run cargo clippy --fix

* cargo fmt

* add rust-toolchain.toml

* force rust version

* fixup! run cargo clippy --fix

fix urls

* add clippy and rustfmt

* update command docs

* export Zip on Windows

* remove benchmarking for a while
remotes/origin/use-bnz
Gal Schlezinger 9 months ago committed by GitHub
parent
commit
ced2f306b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 151
      .github/workflows/rust.yml
  2. 52
      docs/commands.md
  3. 3
      rust-toolchain.toml
  4. 4
      src/arch.rs
  5. 4
      src/archive/mod.rs
  6. 2
      src/commands/env.rs
  7. 2
      src/commands/install.rs
  8. 2
      src/commands/use.rs
  9. 4
      src/config.rs
  10. 6
      src/shell/bash.rs
  11. 6
      src/shell/fish.rs
  12. 2
      src/shell/infer/mod.rs
  13. 6
      src/shell/powershell.rs
  14. 6
      src/shell/zsh.rs

151
.github/workflows/rust.yml

@ -10,13 +10,16 @@ concurrency:
group: ci-${{ github.head_ref }} group: ci-${{ github.head_ref }}
cancel-in-progress: true cancel-in-progress: true
env:
RUST_VERSION: "1.78"
jobs: jobs:
fmt: fmt:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: cargo fmt - name: cargo fmt
@ -27,7 +30,7 @@ jobs:
steps: steps:
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: cargo clippy - name: cargo clippy
@ -41,7 +44,7 @@ jobs:
steps: steps:
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Run tests - name: Run tests
@ -53,7 +56,7 @@ jobs:
steps: steps:
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Build release binary - name: Build release binary
@ -71,7 +74,7 @@ jobs:
steps: steps:
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Build release binary - name: Build release binary
@ -237,7 +240,7 @@ jobs:
steps: steps:
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
targets: x86_64-unknown-linux-musl targets: x86_64-unknown-linux-musl
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
@ -278,7 +281,7 @@ jobs:
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
- uses: hecrj/setup-rust-action@v1 - uses: hecrj/setup-rust-action@v1
with: with:
rust-version: stable rust-version: ${{env.RUST_VERSION}}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
key: arm-binary-${{ matrix.arch }} key: arm-binary-${{ matrix.arch }}
@ -358,70 +361,70 @@ jobs:
run: | run: |
pnpm run generate-command-docs --check --binary-path=$(which fnm) pnpm run generate-command-docs --check --binary-path=$(which fnm)
run_e2e_benchmarks: # TODO: use bnz
runs-on: ubuntu-latest # run_e2e_benchmarks:
name: bench/linux # runs-on: ubuntu-latest
needs: [build_static_linux_binary] # name: bench/linux
permissions: # needs: [build_static_linux_binary]
contents: write # permissions:
pull-requests: write # contents: write
steps: # pull-requests: write
- name: install necessary shells # steps:
run: sudo apt-get update && sudo apt-get install -y fish zsh bash hyperfine # - name: install necessary shells
- uses: actions/checkout@v3 # run: sudo apt-get update && sudo apt-get install -y fish zsh bash hyperfine
- uses: actions/download-artifact@v3 # - uses: actions/checkout@v3
with: # - uses: actions/download-artifact@v3
name: fnm-linux # with:
path: target/release # name: fnm-linux
- name: mark binary as executable # path: target/release
run: chmod +x target/release/fnm # - name: mark binary as executable
- name: install fnm as binary # run: chmod +x target/release/fnm
run: | # - name: install fnm as binary
sudo install target/release/fnm /bin # run: |
fnm --version # sudo install target/release/fnm /bin
- uses: pnpm/action-setup@v2.2.4 # fnm --version
with: # - uses: pnpm/action-setup@v2.2.4
run_install: false # with:
- uses: actions/setup-node@v3 # run_install: false
with: # - uses: actions/setup-node@v3
node-version: 18.x # with:
cache: "pnpm" # node-version: 18.x
- name: Get pnpm store directory # cache: "pnpm"
id: pnpm-cache # - name: Get pnpm store directory
run: | # id: pnpm-cache
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" # run: |
- uses: actions/cache@v3 # echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
name: Setup pnpm cache # - uses: actions/cache@v3
with: # name: Setup pnpm cache
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} # with:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} # path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
restore-keys: | # key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
${{ runner.os }}-pnpm-store- # restore-keys: |
- run: pnpm install # ${{ runner.os }}-pnpm-store-
- name: Run benchmarks # - run: pnpm install
env: # - name: Run benchmarks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # env:
SHOULD_STORE: ${{ toJson(!github.event.pull_request) }} # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: benchmark # SHOULD_STORE: ${{ toJson(!github.event.pull_request) }}
run: | # id: benchmark
delimiter="$(openssl rand -hex 8)" # run: |
echo "markdown<<${delimiter}" >> "${GITHUB_OUTPUT}" # delimiter="$(openssl rand -hex 8)"
node benchmarks/run.mjs --store=$SHOULD_STORE >> "${GITHUB_OUTPUT}" # echo "markdown<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}" # node benchmarks/run.mjs --store=$SHOULD_STORE >> "${GITHUB_OUTPUT}"
# echo "${delimiter}" >> "${GITHUB_OUTPUT}"
- name: Create a PR comment # - name: Create a PR comment
if: ${{ github.event.pull_request }} # if: ${{ github.event.pull_request }}
uses: thollander/actions-comment-pull-request@v2 # uses: thollander/actions-comment-pull-request@v2
with: # with:
message: | # message: |
## Linux Benchmarks for ${{ github.event.pull_request.head.sha }} # ## Linux Benchmarks for ${{ github.event.pull_request.head.sha }}
${{ steps.benchmark.outputs.markdown }} # ${{ steps.benchmark.outputs.markdown }}
comment_tag: "benchy comment" # comment_tag: "benchy comment"
#
- name: Create a commit comment # - name: Create a commit comment
if: ${{ !github.event.pull_request }} # if: ${{ !github.event.pull_request }}
uses: peter-evans/commit-comment@v2 # uses: peter-evans/commit-comment@v2
with: # with:
body: | # body: |
## Linux Benchmarks # ## Linux Benchmarks
${{ steps.benchmark.outputs.markdown }} # ${{ steps.benchmark.outputs.markdown }}

52
docs/commands.md

@ -22,7 +22,7 @@ Commands:
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -55,7 +55,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -82,7 +82,7 @@ Usage: fnm list-remote [OPTIONS]
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -115,7 +115,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -139,7 +139,7 @@ Usage: fnm list [OPTIONS]
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -172,7 +172,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -203,7 +203,7 @@ Options:
Install latest LTS Install latest LTS
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -242,7 +242,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -273,7 +273,7 @@ Options:
Install the version if it isn't installed yet Install the version if it isn't installed yet
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -309,7 +309,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -337,7 +337,7 @@ Usage: fnm env [OPTIONS]
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -381,7 +381,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -405,7 +405,7 @@ Usage: fnm completions [OPTIONS]
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -443,7 +443,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -474,7 +474,7 @@ Arguments:
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -507,7 +507,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -535,7 +535,7 @@ Arguments:
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -568,7 +568,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -598,7 +598,7 @@ Arguments:
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -631,7 +631,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -655,7 +655,7 @@ Usage: fnm current [OPTIONS]
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -688,7 +688,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -721,7 +721,7 @@ Arguments:
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -757,7 +757,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]
@ -787,7 +787,7 @@ Arguments:
Options: Options:
--node-dist-mirror <NODE_DIST_MIRROR> --node-dist-mirror <NODE_DIST_MIRROR>
https://nodejs.org/dist/ mirror <https://nodejs.org/dist/> mirror
[env: FNM_NODE_DIST_MIRROR] [env: FNM_NODE_DIST_MIRROR]
[default: https://nodejs.org/dist] [default: https://nodejs.org/dist]
@ -820,7 +820,7 @@ Options:
- recursive: Use the version of Node defined within the current directory and all parent directories - recursive: Use the version of Node defined within the current directory and all parent directories
--corepack-enabled --corepack-enabled
Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see https://nodejs.org/api/corepack.html Enable corepack support for each new installation. This will make fnm call `corepack enable` on every Node.js installation. For more information about corepack see <https://nodejs.org/api/corepack.html>
[env: FNM_COREPACK_ENABLED] [env: FNM_COREPACK_ENABLED]

3
rust-toolchain.toml

@ -0,0 +1,3 @@
[toolchain]
channel = "1.78"
components = ["rustfmt", "clippy"]

4
src/arch.rs

@ -17,10 +17,10 @@ pub enum Arch {
pub fn get_safe_arch<'a>(arch: &'a Arch, version: &Version) -> &'a Arch { pub fn get_safe_arch<'a>(arch: &'a Arch, version: &Version) -> &'a Arch {
use crate::system_info::{platform_arch, platform_name}; use crate::system_info::{platform_arch, platform_name};
return match (platform_name(), platform_arch(), version) { match (platform_name(), platform_arch(), version) {
("darwin", "arm64", Version::Semver(v)) if v.major < 16 => &Arch::X64, ("darwin", "arm64", Version::Semver(v)) if v.major < 16 => &Arch::X64,
_ => arch, _ => arch,
}; }
} }
#[cfg(windows)] #[cfg(windows)]

4
src/archive/mod.rs

@ -3,5 +3,9 @@ pub mod tar_xz;
pub mod zip; pub mod zip;
pub use self::extract::{Error, Extract}; pub use self::extract::{Error, Extract};
#[cfg(unix)]
pub use self::tar_xz::TarXz; pub use self::tar_xz::TarXz;
#[cfg(windows)]
pub use self::zip::Zip; pub use self::zip::Zip;

2
src/commands/env.rs

@ -44,7 +44,7 @@ fn make_symlink(config: &FnmConfig) -> Result<std::path::PathBuf, Error> {
} }
match symlink_dir(config.default_version_dir(), &temp_dir) { match symlink_dir(config.default_version_dir(), &temp_dir) {
Ok(_) => Ok(temp_dir), Ok(()) => Ok(temp_dir),
Err(source) => Err(Error::CantCreateSymlink { source, temp_dir }), Err(source) => Err(Error::CantCreateSymlink { source, temp_dir }),
} }
} }

2
src/commands/install.rs

@ -147,7 +147,7 @@ impl Command for Install {
outln!(config, Error, "{} {}", "warning:".bold().yellow(), err); outln!(config, Error, "{} {}", "warning:".bold().yellow(), err);
} }
Err(source) => Err(Error::DownloadError { source })?, Err(source) => Err(Error::DownloadError { source })?,
Ok(_) => {} Ok(()) => {}
}; };
if config.corepack_enabled() { if config.corepack_enabled() {

2
src/commands/use.rs

@ -153,7 +153,7 @@ fn install_new_version(
fn replace_symlink(from: &std::path::Path, to: &std::path::Path) -> std::io::Result<()> { fn replace_symlink(from: &std::path::Path, to: &std::path::Path) -> std::io::Result<()> {
let symlink_deletion_result = fs::remove_symlink_dir(to); let symlink_deletion_result = fs::remove_symlink_dir(to);
match fs::symlink_dir(from, to) { match fs::symlink_dir(from, to) {
ok @ Ok(_) => ok, ok @ Ok(()) => ok,
err @ Err(_) => symlink_deletion_result.and(err), err @ Err(_) => symlink_deletion_result.and(err),
} }
} }

4
src/config.rs

@ -7,7 +7,7 @@ use url::Url;
#[derive(clap::Parser, Debug)] #[derive(clap::Parser, Debug)]
pub struct FnmConfig { pub struct FnmConfig {
/// https://nodejs.org/dist/ mirror /// <https://nodejs.org/dist/> mirror
#[clap( #[clap(
long, long,
env = "FNM_NODE_DIST_MIRROR", env = "FNM_NODE_DIST_MIRROR",
@ -67,7 +67,7 @@ pub struct FnmConfig {
/// Enable corepack support for each new installation. /// Enable corepack support for each new installation.
/// This will make fnm call `corepack enable` on every Node.js installation. /// This will make fnm call `corepack enable` on every Node.js installation.
/// For more information about corepack see https://nodejs.org/api/corepack.html /// For more information about corepack see <https://nodejs.org/api/corepack.html>
#[clap( #[clap(
long, long,
env = "FNM_COREPACK_ENABLED", env = "FNM_COREPACK_ENABLED",

6
src/shell/bash.rs

@ -28,13 +28,13 @@ impl Shell for Bash {
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {
let autoload_hook = match config.version_file_strategy() { let autoload_hook = match config.version_file_strategy() {
VersionFileStrategy::Local => indoc!( VersionFileStrategy::Local => indoc!(
r#" r"
if [[ -f .node-version || -f .nvmrc ]]; then if [[ -f .node-version || -f .nvmrc ]]; then
fnm use --silent-if-unchanged fnm use --silent-if-unchanged
fi fi
"# "
), ),
VersionFileStrategy::Recursive => r#"fnm use --silent-if-unchanged"#, VersionFileStrategy::Recursive => r"fnm use --silent-if-unchanged",
}; };
Ok(formatdoc!( Ok(formatdoc!(
r#" r#"

6
src/shell/fish.rs

@ -28,13 +28,13 @@ impl Shell for Fish {
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {
let autoload_hook = match config.version_file_strategy() { let autoload_hook = match config.version_file_strategy() {
VersionFileStrategy::Local => indoc!( VersionFileStrategy::Local => indoc!(
r#" r"
if test -f .node-version -o -f .nvmrc if test -f .node-version -o -f .nvmrc
fnm use --silent-if-unchanged fnm use --silent-if-unchanged
end end
"# "
), ),
VersionFileStrategy::Recursive => r#"fnm use --silent-if-unchanged"#, VersionFileStrategy::Recursive => r"fnm use --silent-if-unchanged",
}; };
Ok(formatdoc!( Ok(formatdoc!(
r#" r#"

2
src/shell/infer/mod.rs

@ -7,7 +7,7 @@ pub use self::unix::infer_shell;
#[cfg(not(unix))] #[cfg(not(unix))]
pub use self::windows::infer_shell; pub use self::windows::infer_shell;
pub(self) fn shell_from_string(shell: &str) -> Option<Box<dyn super::Shell>> { fn shell_from_string(shell: &str) -> Option<Box<dyn super::Shell>> {
use super::{Bash, Fish, PowerShell, WindowsCmd, Zsh}; use super::{Bash, Fish, PowerShell, WindowsCmd, Zsh};
match shell { match shell {
"sh" | "bash" => return Some(Box::from(Bash)), "sh" | "bash" => return Some(Box::from(Bash)),

6
src/shell/powershell.rs

@ -28,11 +28,11 @@ impl Shell for PowerShell {
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {
let autoload_hook = match config.version_file_strategy() { let autoload_hook = match config.version_file_strategy() {
VersionFileStrategy::Local => indoc!( VersionFileStrategy::Local => indoc!(
r#" r"
If ((Test-Path .nvmrc) -Or (Test-Path .node-version)) { & fnm use --silent-if-unchanged } If ((Test-Path .nvmrc) -Or (Test-Path .node-version)) { & fnm use --silent-if-unchanged }
"# "
), ),
VersionFileStrategy::Recursive => r#"fnm use --silent-if-unchanged"#, VersionFileStrategy::Recursive => r"fnm use --silent-if-unchanged",
}; };
Ok(formatdoc!( Ok(formatdoc!(
r#" r#"

6
src/shell/zsh.rs

@ -32,13 +32,13 @@ impl Shell for Zsh {
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {
let autoload_hook = match config.version_file_strategy() { let autoload_hook = match config.version_file_strategy() {
VersionFileStrategy::Local => indoc!( VersionFileStrategy::Local => indoc!(
r#" r"
if [[ -f .node-version || -f .nvmrc ]]; then if [[ -f .node-version || -f .nvmrc ]]; then
fnm use --silent-if-unchanged fnm use --silent-if-unchanged
fi fi
"# "
), ),
VersionFileStrategy::Recursive => r#"fnm use --silent-if-unchanged"#, VersionFileStrategy::Recursive => r"fnm use --silent-if-unchanged",
}; };
Ok(formatdoc!( Ok(formatdoc!(
r#" r#"

Loading…
Cancel
Save