summaryrefslogtreecommitdiff
path: root/cli/fmt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/fmt.rs')
-rw-r--r--cli/fmt.rs37
1 files changed, 21 insertions, 16 deletions
diff --git a/cli/fmt.rs b/cli/fmt.rs
index 0d7a909bc..229039606 100644
--- a/cli/fmt.rs
+++ b/cli/fmt.rs
@@ -34,23 +34,8 @@ pub async fn format(args: Vec<String>, check: bool) -> Result<(), ErrBox> {
return format_stdin(check);
}
- let mut target_files: Vec<PathBuf> = vec![];
+ let target_files = collect_files(args)?;
- if args.is_empty() {
- target_files.extend(files_in_subtree(
- std::env::current_dir().unwrap(),
- is_supported,
- ));
- } else {
- for arg in args {
- let p = PathBuf::from(arg);
- if p.is_dir() {
- target_files.extend(files_in_subtree(p, is_supported));
- } else {
- target_files.push(p);
- };
- }
- }
let config = get_config();
if check {
check_source_files(config, target_files).await
@@ -222,6 +207,26 @@ fn is_supported(path: &Path) -> bool {
}
}
+pub fn collect_files(files: Vec<String>) -> Result<Vec<PathBuf>, ErrBox> {
+ let mut target_files: Vec<PathBuf> = vec![];
+
+ if files.is_empty() {
+ target_files
+ .extend(files_in_subtree(std::env::current_dir()?, is_supported));
+ } else {
+ for arg in files {
+ let p = PathBuf::from(arg);
+ if p.is_dir() {
+ target_files.extend(files_in_subtree(p, is_supported));
+ } else {
+ target_files.push(p);
+ };
+ }
+ }
+
+ Ok(target_files)
+}
+
fn get_config() -> dprint::configuration::Configuration {
use dprint::configuration::*;
ConfigurationBuilder::new().deno().build()