diff options
Diffstat (limited to 'rust/fatcat-cli/src/main.rs')
-rw-r--r-- | rust/fatcat-cli/src/main.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/rust/fatcat-cli/src/main.rs b/rust/fatcat-cli/src/main.rs index 046a825..75ddc6a 100644 --- a/rust/fatcat-cli/src/main.rs +++ b/rust/fatcat-cli/src/main.rs @@ -163,8 +163,10 @@ enum Command { #[structopt(subcommand)] cmd: EditgroupCommand, }, + Download { + specifier: Specifier, + }, //Changelog - //Download //History Search { entity_type: EntityType, @@ -324,6 +326,49 @@ fn run(opt: Opt) -> Result<()> { .context("updating after edit")?; println!("{}", serde_json::to_string(&ee)?); } + Command::Download{specifier} => { + // run lookups if necessary (inefficient) + let specifier = match specifier { + Specifier::ReleaseLookup(_, _) | Specifier::FileLookup(_, _) => + specifier.into_entity_specifier(&mut api_client)?, + _ => specifier, + }; + let file_entities = match specifier { + Specifier::Release(ident) => { + let result = api_client.rt.block_on( + api_client.api.get_release(ident.clone(), Some("files".to_string()), Some("abstracts,refs".to_string())) + )?; + let release_entity = match result { + fatcat_openapi::GetReleaseResponse::FoundEntity(model) => { + Ok(model) + }, + resp => Err(anyhow!("{:?}", resp)) + .with_context(|| format!("API GET failed: {:?}", ident)), + }?; + // TODO: not unwrap + release_entity.files.unwrap() + }, + Specifier::File(ident) => { + let result = api_client.rt.block_on( + api_client.api.get_file(ident.clone(), None, None) + )?; + let file_entity = match result { + fatcat_openapi::GetFileResponse::FoundEntity(model) => { + Ok(model) + }, + resp => Err(anyhow!("{:?}", resp)) + .with_context(|| format!("API GET failed: {:?}", ident)), + }?; + vec![file_entity] + }, + // TODO: not panic + _ => panic!("TODO: can only fetch file or release"), + }; + for fe in file_entities { + let status = download_file(fe)?; + println!("{:?}", status); + }; + } Command::Search { entity_type, terms, |