Skip to content

Commit

Permalink
Merge #297
Browse files Browse the repository at this point in the history
297: uses clap for the CLI r=kbknapp a=kbknapp



Co-authored-by: Kevin K <kbknapp@gmail.com>
  • Loading branch information
bors[bot] and kbknapp committed Nov 18, 2021
2 parents 4b251ed + b7f652a commit 5bda9e7
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 329 deletions.
22 changes: 2 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Ricky H. <ricky.hosfelt@gmail.com>",
]
categories = ["development-tools", "development-tools::cargo-plugins"]
edition = "2018"
edition = "2021"
exclude = ["*.png"]
keywords = [
"cargo",
Expand All @@ -30,7 +30,6 @@ name = "cargo-outdated"
[dependencies]
anyhow = "1.0"
cargo = "0.57.0"
docopt = "1.1.0"
env_logger = "0.9.0"
git2-curl = "0.14.0"
semver = "1.0.0"
Expand All @@ -40,6 +39,7 @@ serde_json = "1.0.56"
tabwriter = "1.2.1"
tempfile = "3"
toml = "~0.5.0"
clap = "2.33.3"

[dependencies.termcolor]
optional = true
Expand Down
20 changes: 10 additions & 10 deletions src/cargo_ops/elaborate_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
) -> CargoResult<ElaborateWorkspace<'ela>> {
// new in cargo 0.54.0
let flag_features: BTreeSet<FeatureValue> = options
.flag_features
.features
.iter()
.map(|feature| FeatureValue::new(InternedString::from(feature)))
.collect();
Expand Down Expand Up @@ -118,13 +118,13 @@ impl<'ela> ElaborateWorkspace<'ela> {
pkgs,
pkg_deps,
pkg_status: RefCell::new(HashMap::new()),
workspace_mode: options.flag_workspace || workspace.current().is_err(),
workspace_mode: options.workspace || workspace.current().is_err(),
})
}

/// Determine root package based on current workspace and CLI options
pub fn determine_root(&self, options: &Options) -> CargoResult<PackageId> {
if let Some(ref root_name) = options.flag_root {
if let Some(ref root_name) = options.root {
if let Ok(workspace_root) = self.workspace.current() {
if root_name == workspace_root.name().as_str() {
Ok(workspace_root.package_id())
Expand Down Expand Up @@ -239,7 +239,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
self.pkg_status.borrow_mut().insert(path.clone(), status);
// next layer
// this unwrap is safe since we first check if it is None :)
if options.flag_depth.is_none() || depth < options.flag_depth.unwrap() {
if options.depth.is_none() || depth < options.depth.unwrap() {
self.pkg_deps[pkg]
.keys()
.filter(|dep| !path.contains(dep))
Expand Down Expand Up @@ -279,15 +279,15 @@ impl<'ela> ElaborateWorkspace<'ela> {
let pkg = path.last().ok_or(OutdatedError::EmptyPath)?;
let name = pkg.name().to_string();

if options.flag_ignore.contains(&name) {
if options.ignore.contains(&name) {
continue;
}

let depth = path.len() as i32 - 1;
// generate lines
let status = &self.pkg_status.borrow_mut()[&path];
if (status.compat.is_changed() || status.latest.is_changed())
&& (options.flag_packages.is_empty() || options.flag_packages.contains(&name))
&& (options.packages.is_empty() || options.packages.contains(&name))
{
// name version compatible latest kind platform
let parent = path.get(path.len() - 2);
Expand Down Expand Up @@ -326,7 +326,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
}
// next layer
// this unwrap is safe since we first check if it is None :)
if options.flag_depth.is_none() || depth < options.flag_depth.unwrap() {
if options.depth.is_none() || depth < options.depth.unwrap() {
self.pkg_deps[pkg]
.keys()
.filter(|dep| !path.contains(dep))
Expand Down Expand Up @@ -379,15 +379,15 @@ impl<'ela> ElaborateWorkspace<'ela> {
let pkg = path.last().ok_or(OutdatedError::EmptyPath)?;
let name = pkg.name().to_string();

if options.flag_ignore.contains(&name) {
if options.ignore.contains(&name) {
continue;
}

let depth = path.len() as i32 - 1;
// generate lines
let status = &self.pkg_status.borrow_mut()[&path];
if (status.compat.is_changed() || status.latest.is_changed())
&& (options.flag_packages.is_empty() || options.flag_packages.contains(&name))
&& (options.packages.is_empty() || options.packages.contains(&name))
{
// name version compatible latest kind platform
// safely get the parent index
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'ela> ElaborateWorkspace<'ela> {
}
// next layer
// this unwrap is safe since we first check if it is None :)
if options.flag_depth.is_none() || depth < options.flag_depth.unwrap() {
if options.depth.is_none() || depth < options.depth.unwrap() {
self.pkg_deps[pkg]
.keys()
.filter(|dep| !path.contains(dep))
Expand Down
31 changes: 12 additions & 19 deletions src/cargo_ops/temp_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ impl<'tmp> TempProject<'tmp> {
let mut config = Config::new(shell, cwd, homedir);
config.configure(
0,
options.flag_verbose == 0,
options.flag_color.as_deref(),
options.verbose == 0,
Some(&options.color.to_string().to_ascii_lowercase()),
options.frozen(),
options.locked(),
options.flag_offline,
options.offline,
&cargo_home_path,
&[],
&[],
Expand Down Expand Up @@ -396,7 +396,7 @@ impl<'tmp> TempProject<'tmp> {
} else if find_latest {
// this unwrap is safe since we check if `version_req` is `None` before this
// (which is only `None` if `requirement` is `None`)
self.options.flag_aggressive
self.options.aggressive
|| valid_latest_version(requirement.unwrap(), summary.version())
} else {
// this unwrap is safe since we check if `version_req` is `None` before this
Expand Down Expand Up @@ -436,12 +436,7 @@ impl<'tmp> TempProject<'tmp> {
if self.options.all_features() {
return true;
}
if !optional
&& self
.options
.flag_features
.contains(&String::from("default"))
{
if !optional && self.options.features.contains(&String::from("default")) {
return true;
}
let features_table = match *features_table {
Expand All @@ -450,7 +445,7 @@ impl<'tmp> TempProject<'tmp> {
};
let mut to_resolve: Vec<&str> = self
.options
.flag_features
.features
.iter()
.filter(|f| !f.is_empty())
.map(String::as_str)
Expand Down Expand Up @@ -495,7 +490,7 @@ impl<'tmp> TempProject<'tmp> {
// In short this allows cargo to build the package with semver minor compatibilities issues
// https://github.com/rust-lang/cargo/issues/6584
// https://github.com/kbknapp/cargo-outdated/issues/230
if self.options.flag_exclude.contains(&dep_key) {
if self.options.exclude.contains(&dep_key) {
continue;
}

Expand Down Expand Up @@ -682,13 +677,11 @@ impl<'tmp> TempProject<'tmp> {

fn warn<T: ::std::fmt::Display>(&self, message: T) -> CargoResult<()> {
let original_verbosity = self.config.shell().verbosity();
self.config
.shell()
.set_verbosity(if self.options.flag_quiet {
Verbosity::Quiet
} else {
Verbosity::Normal
});
self.config.shell().set_verbosity(if self.options.quiet {
Verbosity::Quiet
} else {
Verbosity::Normal
});
self.config.shell().warn(message)?;
self.config.shell().set_verbosity(original_verbosity);
Ok(())
Expand Down
Loading

0 comments on commit 5bda9e7

Please sign in to comment.