Another autoformat

This commit is contained in:
2025-07-20 17:36:49 -05:00
parent 04dd333d72
commit 0e3aa16e00
3 changed files with 22 additions and 21 deletions

View File

@@ -166,10 +166,10 @@ impl TryFrom<&Table> for PartialConfig {
type Error = crate::config::Error; type Error = crate::config::Error;
/// Scans properties out of a `toml::Table` to get a PartialConfig. /// Scans properties out of a `toml::Table` to get a PartialConfig.
/// ///
/// `Error::NoSuchProperty` is quietly ignored (mapped to `None`) since it /// `Error::NoSuchProperty` is quietly ignored (mapped to `None`) since it
/// isn't an error in this context. /// isn't an error in this context.
/// ///
/// All other errors are propagated and should be treated as real failures. /// All other errors are propagated and should be treated as real failures.
fn try_from(value: &Table) -> Result<Self> { fn try_from(value: &Table) -> Result<Self> {
Ok(Self { Ok(Self {
@@ -315,8 +315,8 @@ mod tests {
let load_result = get_config("/some/other/path", search_paths)?; let load_result = get_config("/some/other/path", search_paths)?;
let expected = PartialConfig { let expected = PartialConfig {
project_path: Some(String::from("/some/other/path")), project_path: Some(String::from("/some/other/path")),
gitea_url: Some(String::from("fake-url")), gitea_url: Some(String::from("fake-url")),
..PartialConfig::default() ..PartialConfig::default()
}; };
assert_eq!(load_result, expected); assert_eq!(load_result, expected);
Ok(()) Ok(())
@@ -334,7 +334,9 @@ mod tests {
"./test_data/not_real_5.toml", "./test_data/not_real_5.toml",
"./test_data/sample_config.toml", "./test_data/sample_config.toml",
"./test_data/not_real_6.toml", "./test_data/not_real_6.toml",
].into_iter().map(PathBuf::from); ]
.into_iter()
.map(PathBuf::from);
let load_result = get_config("/home/robert/projects/gt-tool", search_paths)?; let load_result = get_config("/home/robert/projects/gt-tool", search_paths)?;
let expected = PartialConfig { let expected = PartialConfig {
project_path: Some(String::from("/home/robert/projects/gt-tool")), project_path: Some(String::from("/home/robert/projects/gt-tool")),

View File

@@ -20,7 +20,7 @@ pub(crate) async fn decode_client_error(response: reqwest::Response) -> Result<A
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
Placeholder, // TODO: Enumerate error modes Placeholder, // TODO: Enumerate error modes
MissingGiteaUrl, // the gitea URL wasn't specified on the CLI, env, or config file. MissingGiteaUrl, // the gitea URL wasn't specified on the CLI, env, or config file.
MissingRepoFRQN, // either the owner, repo, or both weren't specified in the loaded PartialConfig MissingRepoFRQN, // either the owner, repo, or both weren't specified in the loaded PartialConfig
WrappedConfigErr(config::Error), WrappedConfigErr(config::Error),

View File

@@ -15,31 +15,34 @@ async fn main() -> Result<(), gt_tool::Error> {
// TODO: Heuristics to guess project path // TODO: Heuristics to guess project path
// See issue #8: https://git.gelvin.dev/robert/gt-tool/issues/8 // See issue #8: https://git.gelvin.dev/robert/gt-tool/issues/8
let pwd = std::env::current_dir() let pwd = std::env::current_dir()
.map_err(|_e| gt_tool::Error::WrappedConfigErr( .map_err(|_e| gt_tool::Error::WrappedConfigErr(gt_tool::config::Error::CouldntReadFile))?;
gt_tool::config::Error::CouldntReadFile
))?;
let config = gt_tool::config::get_config( let config = gt_tool::config::get_config(
pwd.to_str().expect("I assumed the path can be UTF-8, but that didn't work out..."), pwd.to_str()
gt_tool::config::default_paths() .expect("I assumed the path can be UTF-8, but that didn't work out..."),
gt_tool::config::default_paths(),
)?; )?;
println!("->> Loaded Config: {config:?}"); println!("->> Loaded Config: {config:?}");
// arg parser also checks the environment. Prefer CLI/env, then config file. // arg parser also checks the environment. Prefer CLI/env, then config file.
let gitea_url = args.gitea_url.or(config.gitea_url).ok_or(gt_tool::Error::MissingGiteaUrl)?; let gitea_url = args
.gitea_url
.or(config.gitea_url)
.ok_or(gt_tool::Error::MissingGiteaUrl)?;
// Config files split the repo FQRN into "owner" and "repo" (confusing naming, sorry) // Config files split the repo FQRN into "owner" and "repo" (confusing naming, sorry)
// These must be merged back together and passed along. // These must be merged back together and passed along.
let conf_fqrn = config.owner let conf_fqrn = config
.owner
.ok_or(gt_tool::Error::MissingRepoFRQN) .ok_or(gt_tool::Error::MissingRepoFRQN)
.and_then(| mut own| { .and_then(|mut own| {
let repo = config.repo.ok_or(gt_tool::Error::MissingRepoFRQN)?; let repo = config.repo.ok_or(gt_tool::Error::MissingRepoFRQN)?;
own.push_str("/"); own.push_str("/");
own.push_str(&repo); own.push_str(&repo);
Ok(own) Ok(own)
}); });
let repo_fqrn = args.repo let repo_fqrn = args
.repo
.ok_or(gt_tool::Error::MissingRepoFRQN) .ok_or(gt_tool::Error::MissingRepoFRQN)
.or(conf_fqrn)?; .or(conf_fqrn)?;
let mut headers = reqwest::header::HeaderMap::new(); let mut headers = reqwest::header::HeaderMap::new();
headers.append(ACCEPT, header::HeaderValue::from_static("application/json")); headers.append(ACCEPT, header::HeaderValue::from_static("application/json"));
@@ -121,11 +124,7 @@ async fn main() -> Result<(), gt_tool::Error> {
} }
for file in files { for file in files {
let _attach_desc = gt_tool::api::release_attachment::create_release_attachment( let _attach_desc = gt_tool::api::release_attachment::create_release_attachment(
&client, &client, &gitea_url, &repo_fqrn, release.id, file,
&gitea_url,
&repo_fqrn,
release.id,
file,
) )
.await?; .await?;
} }