From 69afa9a804cecf030e1eda69a905fe607c8a016e Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Thu, 16 Nov 2023 03:01:04 -0500 Subject: [PATCH] adds --skip and --limit options --- src/publish.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/publish.rs b/src/publish.rs index f84990d..3c2e9fa 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -40,6 +40,17 @@ struct Opt { /// the config file. #[clap(long, value_name = "REGEX", alias = "filter")] pub filter_crates: Option, + + /// Option to limit the number of crate versions published. If set, when the + /// number is reached the program will exit. + #[clap(long, short = 'n', value_name = "INT")] + pub limit: Option, + + /// Option to skip a number of crate versions at the beginning of the dependency + /// order, for use if resuming. The skipped versions will not count as part of + /// the optional --limit. + #[clap(long, value_name = "INT")] + pub skip: Option, } #[derive(Debug, Clone, Deserialize)] @@ -707,7 +718,7 @@ fn prepare_source_dirs_for_publish( fn cargo_publish_modified_source_dir(config: &Config, meta: &VersionMeta) -> Result<(), Error> { let begin = Instant::now(); - info!(name = %meta.index_meta.name, vers = %meta.index_meta.vers, "publishing crate version"); + debug!(name = %meta.index_meta.name, vers = %meta.index_meta.vers, "publishing crate version"); let index_env_key = format!( "CARGO_REGISTRIES_{}_INDEX", config.dst.registry_name.to_case(Case::ScreamingSnake) @@ -858,7 +869,11 @@ fn main() -> Result<(), Error> { .flat_map(|(k, v)| v.iter().map(|m| ((k.as_str(), &m.index_meta.vers), m))) .collect(); - for row in publish_log.iter() { + let skip = opt.skip.unwrap_or(0); + let limit = opt.limit.unwrap_or(publish_log.len()); + debug!(skip, limit, n_total_versions = publish_log.len(), "ready to publish!"); + + for row in publish_log.iter().skip(skip).take(limit) { let Some(meta) = by_name_vers.remove(&(row.crate_name.as_str(), &row.version)) else { warn!( ?row,