Skip to content

Commit

Permalink
Fix format option in configuration file (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
mre authored Oct 27, 2024
1 parent e43086c commit 812941c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions fixtures/configs/format.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
format = "json"
4 changes: 3 additions & 1 deletion lychee-bin/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ const TIMEOUT_STR: &str = concatcp!(DEFAULT_TIMEOUT_SECS);
const RETRY_WAIT_TIME_STR: &str = concatcp!(DEFAULT_RETRY_WAIT_TIME_SECS);

/// The format to use for the final status report
#[derive(Debug, Deserialize, Default, Clone, Display, EnumIter, VariantNames)]
#[derive(Debug, Deserialize, Default, Clone, Display, EnumIter, VariantNames, PartialEq)]
#[non_exhaustive]
#[strum(serialize_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub(crate) enum StatsFormat {
#[default]
Compact,
Expand Down Expand Up @@ -544,6 +545,7 @@ impl Config {
exclude_link_local: false;
exclude_loopback: false;
exclude_mail: false;
format: StatsFormat::default();
remap: Vec::<String>::new();
fallback_extensions: Vec::<String>::new();
header: Vec::<String>::new();
Expand Down
22 changes: 22 additions & 0 deletions lychee-bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,4 +1723,26 @@ mod cli {

Ok(())
}

#[tokio::test]
async fn test_json_format_in_config() -> Result<()> {
let mock_server = mock_server!(StatusCode::OK);
let config = fixtures_path().join("configs").join("format.toml");
let mut cmd = main_command();
cmd.arg("--config")
.arg(config)
.arg("-")
.write_stdin(mock_server.uri())
.env_clear()
.assert()
.success();

// Check that the output is in JSON format
let output = cmd.output().unwrap();
let output = std::str::from_utf8(&output.stdout).unwrap();
let json: serde_json::Value = serde_json::from_str(output)?;
assert_eq!(json["total"], 1);

Ok(())
}
}

0 comments on commit 812941c

Please sign in to comment.