Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore locally installed packages when importing #22

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Options:
Default: `false`, i.e. return an error in case the file
already exists.

-k, --keep-self
-s, --keep-self
Also import this `cargo-liner` package into the
configuration, for example in order to specify a certain
version requirement later on.
Expand All @@ -440,6 +440,15 @@ Options:
configuration file. Note however that the `ship` command
will still self-update by default.

-l, --keep-local
Also import all locally-installed packages into the
configuration. This means packages installed via `cargo
install --path <path>` will be present in the configuration.

Default: `false`, i.e. exclude all packages installed via
`cargo install --path <path>` from the list of packages to
install or update in the resulting configuration file.

-v, --verbose...
Be more verbose. Use multiple times to be more and more so
each time.
Expand Down
8 changes: 4 additions & 4 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ mod tests {
let _lk = LOCK.lock();
let _reg = testing::init_registry();
testing::fake_publish_all([
(SELF, clap::crate_version!()),
("cargo-expand", "1.0.79"),
("cargo-tarpaulin", "0.27.3"),
("bat", "0.24.0"),
(SELF, clap::crate_version!(), false),
("cargo-expand", "1.0.79", false),
("cargo-tarpaulin", "0.27.3", false),
("bat", "0.24.0", false),
]);
testing::set_env();

Expand Down
47 changes: 46 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,17 @@ pub struct ImportArgs {
/// Default: `false`, i.e. exclude the current package from the list of
/// packages to install or update in the resulting configuration file. Note
/// however that the `ship` command will still self-update by default.
#[arg(short, long)]
#[arg(short = 's', long)]
pub keep_self: bool,

/// Also import all locally-installed packages into the configuration. This
/// means packages installed via `cargo install --path <path>` will be present
/// in the configuration.
///
/// Default: `false`, i.e. exclude all packages installed via `cargo install --path <path>`
/// from the list of packages to install or update in the resulting configuration file.
#[arg(short = 'l', long)]
pub keep_local: bool,
}

#[cfg(test)]
Expand Down Expand Up @@ -427,6 +436,7 @@ mod tests {
patch: false,
force: false,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -446,6 +456,7 @@ mod tests {
patch: false,
force: true,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -465,6 +476,7 @@ mod tests {
patch: false,
force: false,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -484,6 +496,7 @@ mod tests {
patch: false,
force: true,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -503,6 +516,7 @@ mod tests {
patch: false,
force: false,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -523,6 +537,7 @@ mod tests {
patch: false,
force: true,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -542,6 +557,7 @@ mod tests {
patch: true,
force: false,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -561,6 +577,7 @@ mod tests {
patch: true,
force: true,
keep_self: false,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -580,6 +597,27 @@ mod tests {
patch: false,
force: false,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
color: ColorChoice::Auto,
}),
);
}

#[test]
fn test_import_local() {
assert_eq!(
CargoArgs::try_parse_from(["cargo", "liner", "import", "--keep-local"]).unwrap(),
CargoArgs::Liner(LinerArgs {
command: Some(LinerCommands::Import(ImportArgs {
exact: false,
compatible: false,
patch: false,
force: false,
keep_self: false,
keep_local: true
})),
verbose: 0,
quiet: 0,
Expand All @@ -600,6 +638,7 @@ mod tests {
patch: false,
force: true,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -620,6 +659,7 @@ mod tests {
patch: false,
force: false,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand Down Expand Up @@ -647,6 +687,7 @@ mod tests {
patch: false,
force: true,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -667,6 +708,7 @@ mod tests {
patch: false,
force: false,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand Down Expand Up @@ -694,6 +736,7 @@ mod tests {
patch: false,
force: true,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand All @@ -714,6 +757,7 @@ mod tests {
patch: true,
force: false,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand Down Expand Up @@ -741,6 +785,7 @@ mod tests {
patch: true,
force: true,
keep_self: true,
keep_local: false
})),
verbose: 0,
quiet: 0,
Expand Down
Loading