-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4187933
commit ab488aa
Showing
6 changed files
with
609 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::{ | ||
path::{Path, PathBuf}, | ||
sync::{atomic::AtomicUsize, Arc}, | ||
}; | ||
|
||
use clap::{ArgMatches, Command}; | ||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; | ||
|
||
use crate::Error; | ||
|
||
#[must_use] | ||
pub fn cli() -> Command { | ||
Command::new("fmt").about("Format the config files").arg( | ||
clap::Arg::new("path") | ||
.help("Path to the config file or a folder to recursively fix") | ||
.required(true), | ||
) | ||
} | ||
|
||
/// Execute the convert command | ||
/// | ||
/// # Errors | ||
/// [`Error`] depending on the modules | ||
pub fn execute(matches: &ArgMatches) -> Result<(), Error> { | ||
let path = PathBuf::from(matches.get_one::<String>("path").expect("required")); | ||
if path.is_dir() { | ||
let count = Arc::new(AtomicUsize::new(0)); | ||
let entries = walkdir::WalkDir::new(&path) | ||
.into_iter() | ||
.collect::<Result<Vec<_>, _>>()?; | ||
entries | ||
.par_iter() | ||
.map(|entry| { | ||
if entry.file_type().is_file() | ||
&& entry.path().extension().unwrap_or_default() == "cpp" | ||
&& entry.path().extension().unwrap_or_default() == "hpp" | ||
&& file(entry.path())? | ||
{ | ||
count.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
info!("Format `{}`", entry.path().display()); | ||
} | ||
Ok(()) | ||
}) | ||
.collect::<Result<Vec<_>, Error>>()?; | ||
info!( | ||
"Format {} files", | ||
count.load(std::sync::atomic::Ordering::Relaxed) | ||
); | ||
} else if file(&path)? { | ||
info!("Format `{}`", path.display()); | ||
} else { | ||
info!("No changes in `{}`", path.display()); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn file(path: &Path) -> Result<bool, Error> { | ||
// TODO do not release this lmao | ||
let content = std::fs::read_to_string(path)?; | ||
println!( | ||
"{}", | ||
hemtt_config::fmt::format(&content).expect("errors later") | ||
); | ||
Ok(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
mod fmt; | ||
|
||
use clap::{ArgMatches, Command}; | ||
|
||
use crate::Error; | ||
|
||
#[must_use] | ||
pub fn cli() -> Command { | ||
Command::new("config") | ||
.about("Commands for Config files") | ||
.arg_required_else_help(true) | ||
.subcommand(fmt::cli()) | ||
} | ||
|
||
/// Execute the paa command | ||
/// | ||
/// # Errors | ||
/// [`Error`] depending on the modules | ||
/// | ||
/// # Panics | ||
/// If the args are not present from clap | ||
pub fn execute(matches: &ArgMatches) -> Result<(), Error> { | ||
match matches.subcommand() { | ||
Some(("fmt", matches)) => fmt::execute(matches), | ||
|
||
_ => unreachable!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod config; | ||
pub mod inspect; | ||
pub mod paa; | ||
pub mod pbo; | ||
|
Oops, something went wrong.