Skip to content
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
83 changes: 79 additions & 4 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ toml_edit = "0.22.22"
indexmap = "2"
url = "2.5.4"
pathdiff = "0.2"
env_logger = "0.11.8"
clap-verbosity-flag = "3.0.2"
log = "0.4.27"

[dependencies.semver]
features = ["serde"]
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ Upgrade dependency version requirements in Cargo.toml manifest files
Usage: cargo upgrade [OPTIONS]

Options:
--dry-run Print changes to be made without making them
-n, --dry-run Print changes to be made without making them
--manifest-path <PATH> Path to the manifest to upgrade
--rust-version <VER> Override `rust-version`
--ignore-rust-version Ignore `rust-version` specification in packages
--locked Require `Cargo.toml` to be up to date
-v, --verbose... Use verbose output
-v, --verbose... Increase logging verbosity
-q, --quiet... Decrease logging verbosity
-Z <FLAG> Unstable (nightly-only) flags
-h, --help Print help
-V, --version Print version
Expand Down Expand Up @@ -132,10 +133,12 @@ Options:
-p, --package <PKGID> Package id of the crate to change the version of
--all [deprecated in favor of `--workspace`]
--workspace Modify all packages in the workspace
--dry-run Print changes to be made without making them
-n, --dry-run Print changes to be made without making them
--exclude <EXCLUDE> Crates to exclude and not modify
--offline Run without accessing the network
--locked Require `Cargo.toml` to be up to date
-v, --verbose... Increase logging verbosity
-q, --quiet... Decrease logging verbosity
-Z <FLAG> Unstable (nightly-only) flags
-h, --help Print help
-V, --version Print version
Expand Down
10 changes: 9 additions & 1 deletion src/bin/set-version/set_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct VersionArgs {
workspace: bool,

/// Print changes to be made without making them.
#[arg(long)]
#[arg(long, short = 'n')]
dry_run: bool,

/// Crates to exclude and not modify.
Expand All @@ -68,6 +68,9 @@ pub struct VersionArgs {
#[arg(long)]
locked: bool,

#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,

/// Unstable (nightly-only) flags
#[arg(short = 'Z', value_name = "FLAG", global = true, value_enum)]
unstable_features: Vec<UnstableOptions>,
Expand All @@ -85,6 +88,10 @@ enum UnstableOptions {}
/// Main processing function. Allows us to return a `Result` so that `main` can print pretty error
/// messages.
fn exec(args: VersionArgs) -> CargoResult<()> {
env_logger::Builder::from_env("CARGO_LOG")
.filter_level(args.verbose.log_level_filter())
.init();

let VersionArgs {
target,
bump,
Expand All @@ -97,6 +104,7 @@ fn exec(args: VersionArgs) -> CargoResult<()> {
exclude,
locked,
offline,
verbose: _,
unstable_features: _,
} = args;

Expand Down
28 changes: 21 additions & 7 deletions src/bin/upgrade/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use termcolor::{Color, ColorSpec};
#[command(version)]
pub struct UpgradeArgs {
/// Print changes to be made without making them.
#[arg(long)]
#[arg(long, short = 'n')]
dry_run: bool,

/// Path to the manifest to upgrade
Expand All @@ -38,9 +38,8 @@ pub struct UpgradeArgs {
#[arg(long)]
locked: bool,

/// Use verbose output
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,

/// Unstable (nightly-only) flags
#[arg(short = 'Z', value_name = "FLAG", global = true, value_enum)]
Expand Down Expand Up @@ -117,8 +116,19 @@ impl UpgradeArgs {
exec(self)
}

fn verbose_num(&self) -> i8 {
match self.verbose.filter() {
clap_verbosity_flag::VerbosityFilter::Off => -1,
clap_verbosity_flag::VerbosityFilter::Error => 0,
clap_verbosity_flag::VerbosityFilter::Warn => 1,
clap_verbosity_flag::VerbosityFilter::Info => 2,
clap_verbosity_flag::VerbosityFilter::Debug => 3,
clap_verbosity_flag::VerbosityFilter::Trace => 4,
}
}

fn is_verbose(&self) -> bool {
0 < self.verbose
0 < self.verbose_num()
}

fn verbose<F>(&self, mut callback: F) -> CargoResult<()>
Expand Down Expand Up @@ -156,6 +166,10 @@ enum UnstableOptions {}
/// Main processing function. Allows us to return a `Result` so that `main` can print pretty error
/// messages.
fn exec(args: UpgradeArgs) -> CargoResult<()> {
env_logger::Builder::from_env("CARGO_LOG")
.filter_level(args.verbose.log_level_filter())
.init();

let offline = false;
let mut index = IndexCache::new(CertsSource::Native);

Expand Down Expand Up @@ -437,7 +451,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
if !table.is_empty() {
let (interesting, uninteresting) = table
.into_iter()
.partition::<Vec<_>, _>(|d| d.show_for(args.verbose));
.partition::<Vec<_>, _>(|d| d.show_for(args.verbose_num()));
print_upgrade(interesting)?;
uninteresting_crates.extend(uninteresting);
}
Expand Down Expand Up @@ -796,7 +810,7 @@ impl Dep {
spec
}

fn show_for(&self, verbosity: u8) -> bool {
fn show_for(&self, verbosity: i8) -> bool {
if 2 <= verbosity {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct RemoteIndex {

impl RemoteIndex {
fn open(url: &Url, certs_source: CertsSource) -> CargoResult<Self> {
log::trace!("opening index entry for {url}");
let url = url.to_string();
let url = tame_index::IndexUrl::NonCratesIo(std::borrow::Cow::Owned(url));
let index = tame_index::SparseIndex::new(tame_index::IndexLocation::new(url))?;
Expand All @@ -212,6 +213,7 @@ impl RemoteIndex {
}

fn krate(&mut self, name: &str) -> CargoResult<Option<IndexKrate>> {
log::trace!("krate {name}");
let etag = self
.etags
.iter()
Expand Down
Loading