summaryrefslogtreecommitdiffstats
path: root/fatcat-cli/src/main.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-02-15 14:00:29 -0800
committerBryan Newbold <bnewbold@archive.org>2021-02-15 14:00:29 -0800
commit5beeca490988227d2d6de9dfc2bdfa7d6798c5df (patch)
tree6f5f54dd2135a9230a4dacc9b891ad647eb113fe /fatcat-cli/src/main.rs
parent4ba6b0507ae09ab3087c317c62bf4d0d19777abe (diff)
downloadfatcat-cli-5beeca490988227d2d6de9dfc2bdfa7d6798c5df.tar.gz
fatcat-cli-5beeca490988227d2d6de9dfc2bdfa7d6798c5df.zip
make fmt
Diffstat (limited to 'fatcat-cli/src/main.rs')
-rw-r--r--fatcat-cli/src/main.rs82
1 files changed, 61 insertions, 21 deletions
diff --git a/fatcat-cli/src/main.rs b/fatcat-cli/src/main.rs
index 4b8322a..f5f5d8b 100644
--- a/fatcat-cli/src/main.rs
+++ b/fatcat-cli/src/main.rs
@@ -1,5 +1,6 @@
use crate::{path_or_stdin, BatchGrouper, BatchOp};
use anyhow::{anyhow, Context, Result};
+use colored_json::to_colored_json_auto;
use fatcat_cli::*;
#[allow(unused_imports)]
use log::{self, debug, info};
@@ -7,7 +8,6 @@ use std::io::Write;
use std::path::PathBuf;
use structopt::StructOpt;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
-use colored_json::to_colored_json_auto;
#[derive(StructOpt)]
#[structopt(rename_all = "kebab-case", about = "CLI interface to Fatcat API")]
@@ -145,7 +145,6 @@ enum BatchCommand {
#[derive(StructOpt)]
enum Command {
-
/// Fetch a single entity, by "ident" or external identifier
Get {
specifier: Specifier,
@@ -387,7 +386,11 @@ fn run(opt: Opt) -> Result<()> {
if toml {
writeln!(&mut std::io::stdout(), "{}", result.to_toml_string()?)?
} else if json || true {
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&result.to_json_value()?)?)?
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&result.to_json_value()?)?
+ )?
}
}
Command::Create {
@@ -396,8 +399,16 @@ fn run(opt: Opt) -> Result<()> {
editgroup_id,
} => {
let json_str = read_entity_file(input_path)?;
- let ee = api_client.create_entity_from_json(entity_type, &json_str, editgroup_id.as_string())?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&ee)?)?)?
+ let ee = api_client.create_entity_from_json(
+ entity_type,
+ &json_str,
+ editgroup_id.as_string(),
+ )?;
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&ee)?)?
+ )?
}
Command::Update {
specifier,
@@ -419,9 +430,16 @@ fn run(opt: Opt) -> Result<()> {
(entity.to_json_string()?, entity.specifier())
}
};
- let ee =
- api_client.update_entity_from_json(exact_specifier, &json_str, editgroup_id.as_string())?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&ee)?)?)?
+ let ee = api_client.update_entity_from_json(
+ exact_specifier,
+ &json_str,
+ editgroup_id.as_string(),
+ )?;
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&ee)?)?
+ )?
}
Command::Edit {
specifier,
@@ -437,7 +455,11 @@ fn run(opt: Opt) -> Result<()> {
json,
editing_command,
)?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&ee)?)?)?
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&ee)?)?
+ )?
}
Command::Changelog { limit, json } => {
let resp = api_client
@@ -503,10 +525,7 @@ fn run(opt: Opt) -> Result<()> {
batch.run(&mut api_client, input_path, BatchOp::Delete, None)?;
}
Command::Batch {
- cmd: BatchCommand::Download {
- jobs,
- output_dir,
- },
+ cmd: BatchCommand::Download { jobs, output_dir },
input_path,
limit,
} => {
@@ -520,7 +539,9 @@ fn run(opt: Opt) -> Result<()> {
return Err(anyhow!("--jobs=0 not implemented"));
}
if jobs > 12 {
- return Err(anyhow!("please don't download more than 12 parallel requests"));
+ return Err(anyhow!(
+ "please don't download more than 12 parallel requests"
+ ));
}
download_batch(input_path, output_dir, limit, jobs)?;
}
@@ -604,7 +625,9 @@ fn run(opt: Opt) -> Result<()> {
let hit = hit?;
match (index_json, entity_json, entity_type) {
(false, false, _) => unreachable!("case handled above"),
- (true, _, _) => writeln!(&mut std::io::stdout(), "{}", hit.to_string())?,
+ (true, _, _) => {
+ writeln!(&mut std::io::stdout(), "{}", hit.to_string())?
+ }
(false, true, SearchEntityType::Release) => {
let specifier =
Specifier::Release(hit["ident"].as_str().unwrap().to_string());
@@ -616,8 +639,9 @@ fn run(opt: Opt) -> Result<()> {
writeln!(&mut std::io::stdout(), "{}", entity.to_json_string()?)?
}
(false, true, SearchEntityType::Container) => {
- let specifier =
- Specifier::Container(hit["ident"].as_str().unwrap().to_string());
+ let specifier = Specifier::Container(
+ hit["ident"].as_str().unwrap().to_string(),
+ );
let entity = specifier.get_from_api(
&mut api_client,
expand.clone(),
@@ -716,25 +740,41 @@ fn run(opt: Opt) -> Result<()> {
cmd: EditgroupsCommand::Create { description },
} => {
let eg = api_client.create_editgroup(Some(description))?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&eg)?)?)?
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&eg)?)?
+ )?
}
Command::Editgroups {
cmd: EditgroupsCommand::Accept { editgroup_id },
} => {
let msg = api_client.accept_editgroup(editgroup_id.as_string())?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&msg)?)?)?
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&msg)?)?
+ )?
}
Command::Editgroups {
cmd: EditgroupsCommand::Submit { editgroup_id },
} => {
let msg = api_client.update_editgroup_submit(editgroup_id.as_string(), true)?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&msg)?)?)?
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&msg)?)?
+ )?
}
Command::Editgroups {
cmd: EditgroupsCommand::Unsubmit { editgroup_id },
} => {
let msg = api_client.update_editgroup_submit(editgroup_id.as_string(), false)?;
- writeln!(&mut std::io::stdout(), "{}", to_colored_json_auto(&serde_json::to_value(&msg)?)?)?
+ writeln!(
+ &mut std::io::stdout(),
+ "{}",
+ to_colored_json_auto(&serde_json::to_value(&msg)?)?
+ )?
}
Command::Status { json } => {
let status = ClientStatus::generate(&mut api_client)?;