Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/fnmPublic

Commit1ebc90d

Browse files
feat(install): adduse flag (#1435)
* feat(install): add `--use` flag* add changeset* update the command docs---------Co-authored-by: Gal Schlezinger <gal@spitfire.co.il>
1 parentddab191 commit1ebc90d

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

‎.changeset/grumpy-dingos-turn.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"fnm":minor
3+
---
4+
5+
add`use` flag to the`install` command

‎docs/commands.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ Options:
262262
[default: info]
263263
[possible values: quiet, error, info]
264264
265+
--use
266+
Use the installed version immediately after installation
267+
265268
--arch <ARCH>
266269
Override the architecture of the installed Node binary. Defaults to arch of fnm binary
267270

‎src/commands/install.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usesuper::command::Command;
2+
usesuper::r#use::Use;
23
usecrate::alias::create_alias;
34
usecrate::arch::get_safe_arch;
45
usecrate::config::FnmConfig;
@@ -8,6 +9,7 @@ use crate::outln;
89
usecrate::progress::ProgressConfig;
910
usecrate::remote_node_index;
1011
usecrate::user_version::UserVersion;
12+
usecrate::user_version_reader::UserVersionReader;
1113
usecrate::version::Version;
1214
usecrate::version_files::get_user_version_for_directory;
1315
use colored::Colorize;
@@ -32,6 +34,10 @@ pub struct Install {
3234
#[clap(long, default_value_t)]
3335
#[arg(value_enum)]
3436
pubprogress:ProgressConfig,
37+
38+
/// Use the installed version immediately after installation
39+
#[clap(long)]
40+
pubr#use:bool,
3541
}
3642

3743
implInstall{
@@ -66,6 +72,7 @@ impl Command for Install {
6672
fnapply(self,config:&FnmConfig) ->Result<(),Self::Error>{
6773
let current_dir = std::env::current_dir().unwrap();
6874
let show_progress =self.progress.enabled(config);
75+
let use_installed =self.r#use;
6976

7077
let current_version =self
7178
.version()?
@@ -165,6 +172,10 @@ impl Command for Install {
165172
enable_corepack(&version, config)?;
166173
}
167174

175+
if use_installed{
176+
use_installed_version(&version, config)?;
177+
}
178+
168179
Ok(())
169180
}
170181
}
@@ -194,6 +205,21 @@ fn enable_corepack(version: &Version, config: &FnmConfig) -> Result<(), Error> {
194205
Ok(())
195206
}
196207

208+
fnuse_installed_version(version:&Version,config:&FnmConfig) ->Result<(),Error>{
209+
Use{
210+
version:Some(UserVersionReader::Direct(UserVersion::Full(
211+
version.clone(),
212+
))),
213+
install_if_missing:false,
214+
silent_if_unchanged:false,
215+
}
216+
.apply(config)
217+
.map_err(|source|Error::UseError{
218+
source:Box::new(source),
219+
})?;
220+
Ok(())
221+
}
222+
197223
#[derive(Debug,Error)]
198224
pubenumError{
199225
#[error("Can't download the requested binary: {}", source)]
@@ -208,6 +234,10 @@ pub enum Error {
208234
#[from]
209235
source:super::exec::Error,
210236
},
237+
#[error(transparent)]
238+
UseError{
239+
source:Box<<UseasCommand>::Error>,
240+
},
211241
#[error("Can't find version in dotfiles. Please provide a version manually to the command.")]
212242
CantInferVersion,
213243
#[error(transparent)]
@@ -244,6 +274,7 @@ mod tests {
244274
lts:false,
245275
latest:false,
246276
progress:ProgressConfig::Never,
277+
r#use:false,
247278
}
248279
.apply(&config)
249280
.expect("Can't install");
@@ -270,6 +301,7 @@ mod tests {
270301
lts:false,
271302
latest:true,
272303
progress:ProgressConfig::Never,
304+
r#use:false,
273305
}
274306
.apply(&config)
275307
.expect("Can't install");

‎src/commands/use.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use thiserror::Error;
1616

1717
#[derive(clap::Parser,Debug)]
1818
pubstructUse{
19-
version:Option<UserVersionReader>,
19+
pubversion:Option<UserVersionReader>,
2020
/// Install the version if it isn't installed yet
2121
#[clap(long)]
22-
install_if_missing:bool,
22+
pubinstall_if_missing:bool,
2323

2424
/// Don't output a message identifying the version being used
2525
/// if it will not change due to execution of this command
2626
#[clap(long)]
27-
silent_if_unchanged:bool,
27+
pubsilent_if_unchanged:bool,
2828
}
2929

3030
implCommandforUse{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp