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

feat: allow for pruning modules based on a list generated by clover #5535

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
68 changes: 68 additions & 0 deletions bin/hoist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,26 @@ struct Args {
#[derive(Subcommand, Debug)]
#[remain::sorted]
enum Commands {
PruneModules(PruneModulesArgs),
UploadAllSpecs(UploadAllSpecsArgs),
UploadSpec(UploadSpecArgs),
WriteAllSpecs(WriteAllSpecsArgs),
WriteExistingModulesSpec(WriteExistingModulesSpecArgs),
WriteSpec(WriteSpecArgs),
}

#[derive(clap::Args, Debug)]
#[command(about = "Remove modules from the module index based on a json list")]
struct PruneModulesArgs {
#[arg(
long,
short = 't',
required = true,
help = "Path to the directory containing specs to remove"
)]
target: PathBuf,
}

#[derive(clap::Args, Debug)]
#[command(about = "Upload all specs in {target_dir} to the module index")]
struct UploadAllSpecsArgs {
Expand All @@ -57,6 +70,7 @@ struct UploadAllSpecsArgs {
)]
max_concurrent: usize,
}

#[derive(clap::Args, Debug)]
#[command(about = "Upload the spec {target} to the module index")]
struct UploadSpecArgs {
Expand Down Expand Up @@ -109,6 +123,7 @@ async fn main() -> Result<()> {
let client = ModuleIndexClient::new(Url::parse(endpoint)?, token);

match args.command {
Some(Commands::PruneModules(args)) => prune_specs(&client, args.target).await?,
Some(Commands::UploadAllSpecs(args)) => {
upload_pkg_specs(&client, args.target_dir, args.max_concurrent).await?
}
Expand Down Expand Up @@ -141,6 +156,59 @@ enum ModuleState {
NeedsUpdate,
New,
}

async fn prune_specs(client: &ModuleIndexClient, target: PathBuf) -> Result<()> {
let buf = fs::read_to_string(&target)?;
let specs_to_remove: HashMap<String, String> = serde_json::from_str(&buf)?;
let modules = list_specs(client.clone()).await?;

let mut modules_to_reject = vec![];

for module in modules {
if !specs_to_remove.contains_key(&module.name) {
continue;
};

modules_to_reject.push((module.name.clone(), module.id));
}

println!("{} modules can be rejected.", modules_to_reject.len());

let mut check = true;
for (module_name, module_id) in modules_to_reject {
let input = if check {
println!("{} will be removed, ok? [y/a/s/n]", module_name);
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
input
} else {
"y".to_string()
};

match input.trim().to_lowercase().as_str() {
"a" => {
check = false;
}
"s" => {
println!("Skipping {}...", module_name);
continue;
}
"y" => {}
_ => return Ok(()),
}
println!("Removing {}...", module_name);

client
.reject_module(
Ulid::from_string(&module_id)?,
CLOVER_DEFAULT_CREATOR.to_string(),
)
.await?;
}

Ok(())
}

async fn write_existing_modules_spec(client: ModuleIndexClient, out: PathBuf) -> Result<()> {
let modules = list_specs(client.clone()).await?;
let mut entries: HashMap<String, String> = HashMap::new();
Expand Down
Loading