Handle multiple file patterns in validate command (#3615)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
6375bd45a6
commit
32a7a9bce4
1 changed files with 21 additions and 19 deletions
|
@ -8,29 +8,35 @@ use surrealdb::sql::parse;
|
||||||
pub struct ValidateCommandArguments {
|
pub struct ValidateCommandArguments {
|
||||||
#[arg(help = "Glob pattern for the files to validate")]
|
#[arg(help = "Glob pattern for the files to validate")]
|
||||||
#[arg(default_value = "**/*.surql")]
|
#[arg(default_value = "**/*.surql")]
|
||||||
pattern: String,
|
patterns: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init(args: ValidateCommandArguments) -> Result<(), Error> {
|
pub async fn init(args: ValidateCommandArguments) -> Result<(), Error> {
|
||||||
let ValidateCommandArguments {
|
let ValidateCommandArguments {
|
||||||
pattern,
|
patterns,
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
let entries = match glob(&pattern) {
|
let mut entries = vec![];
|
||||||
Ok(entries) => entries,
|
|
||||||
Err(error) => {
|
|
||||||
eprintln!("Error parsing glob pattern {pattern}: {error}");
|
|
||||||
|
|
||||||
return Err(Error::Io(IoError::new(
|
for pattern in patterns {
|
||||||
ErrorKind::Other,
|
let pattern_entries = match glob(&pattern) {
|
||||||
format!("Error parsing glob pattern {pattern}: {error}"),
|
Ok(entries) => entries,
|
||||||
)));
|
Err(error) => {
|
||||||
}
|
eprintln!("Error parsing glob pattern {pattern}: {error}");
|
||||||
};
|
|
||||||
|
return Err(Error::Io(IoError::new(
|
||||||
|
ErrorKind::Other,
|
||||||
|
format!("Error parsing glob pattern {pattern}: {error}"),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
entries.extend(pattern_entries.flatten());
|
||||||
|
}
|
||||||
|
|
||||||
let mut has_entries = false;
|
let mut has_entries = false;
|
||||||
|
|
||||||
for entry in entries.flatten() {
|
for entry in entries {
|
||||||
let file_content = tokio::fs::read_to_string(entry.clone()).await?;
|
let file_content = tokio::fs::read_to_string(entry.clone()).await?;
|
||||||
let parse_result = parse(&file_content);
|
let parse_result = parse(&file_content);
|
||||||
|
|
||||||
|
@ -50,12 +56,8 @@ pub async fn init(args: ValidateCommandArguments) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !has_entries {
|
if !has_entries {
|
||||||
eprintln!("No files found for pattern {pattern}");
|
eprintln!("No files found");
|
||||||
|
return Err(Error::Io(IoError::new(ErrorKind::NotFound, "No files found".to_string())));
|
||||||
return Err(Error::Io(IoError::new(
|
|
||||||
ErrorKind::NotFound,
|
|
||||||
format!("No files found for pattern {pattern}"),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue