FmtConfig: use more default

The command argument is required, the other ones can be filled with an
empty value if unspecified. It makes the code simpler.
This commit is contained in:
zimbatm 2021-02-18 11:53:54 +01:00
parent 7a45f41e2a
commit dc9886217a
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
2 changed files with 7 additions and 6 deletions

View File

@ -180,8 +180,8 @@ pub fn create_command_context(treefmt_toml: &PathBuf) -> Result<Vec<CmdContext>>
.map(|config| {
let list_files = glob_to_path(&cwd.to_path_buf(), &config.includes, &config.excludes)?;
Ok(CmdContext {
command: config.command.clone().unwrap_or_default(),
options: config.options.clone().unwrap_or_default(),
command: config.command.clone(),
options: config.options.clone(),
metadata: path_to_filemeta(list_files)?,
})
})

View File

@ -25,16 +25,17 @@ pub struct Root {
/// Config for each formatters
#[derive(Debug, Deserialize)]
pub struct FmtConfig {
/// Command formatter to run
pub command: String,
/// Argument for formatter
#[serde(default)]
pub options: Vec<String>,
/// File or Folder that is included to be formatted
#[serde(default)]
pub includes: Vec<String>,
/// File or Folder that is excluded to be formatted
#[serde(default)]
pub excludes: Vec<String>,
/// Command formatter to run
pub command: Option<String>,
/// Argument for formatter
pub options: Option<Vec<String>>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]