Skip to content

Commit

Permalink
Update queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 17, 2024
1 parent 6f36a15 commit 3f1d634
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 30 deletions.
4 changes: 3 additions & 1 deletion crates/app/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ pub struct QueryTasksArgs {
command: Option<String>,

#[arg(long, help = "Filter tasks that belong to a platform", help_heading = HEADING_FILTERS)]
#[deprecated(note = "Use `toolchain` instead.")]
platform: Option<String>,

#[arg(long, help = "Filter tasks that belong to a project", help_heading = HEADING_FILTERS)]
Expand All @@ -362,6 +363,7 @@ pub async fn tasks(session: CliSession, args: QueryTasksArgs) -> AppResult {
json: args.json,
command: args.command,
query: args.query,
#[allow(deprecated)]
platform: args.platform,
project: args.project,
script: args.script,
Expand Down Expand Up @@ -422,7 +424,7 @@ pub async fn tasks(session: CliSession, args: QueryTasksArgs) -> AppResult {
task_id,
task.command,
task.type_of,
task.platform,
task.toolchains.join(", "),
task.description.as_deref().unwrap_or("...")
))?;
}
Expand Down
13 changes: 6 additions & 7 deletions crates/app/src/queries/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct QueryTasksOptions {
// Filters
pub id: Option<String>,
pub command: Option<String>,
// TODO: Remove in 2.0
pub platform: Option<String>,
pub project: Option<String>,
pub script: Option<String>,
Expand Down Expand Up @@ -46,10 +47,14 @@ fn load_with_regex(
let platform_regex = convert_to_regex("platform", &options.platform)?;
let project_regex = convert_to_regex("project", &options.project)?;
let script_regex = convert_to_regex("script", &options.script)?;
let toolchain_regex = convert_to_regex("toolchain", &options.toolchain)?;
let mut toolchain_regex = convert_to_regex("toolchain", &options.toolchain)?;
let type_regex = convert_to_regex("type", &options.type_of)?;
let mut filtered = vec![];

if toolchain_regex.is_none() {
toolchain_regex = platform_regex;
}

for task in workspace_graph.get_tasks()? {
if let Some(regex) = &id_regex {
if !regex.is_match(&task.id) {
Expand All @@ -75,12 +80,6 @@ fn load_with_regex(
}
}

if let Some(regex) = &platform_regex {
if !regex.is_match(&task.platform.to_string()) {
continue;
}
}

if let Some(regex) = &toolchain_regex {
if !task.toolchains.iter().any(|tc| regex.is_match(&tc)) {
continue;
Expand Down
9 changes: 4 additions & 5 deletions crates/query/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::parser::{parse_query, AstNode, ComparisonOperator, LogicalOperator};
use crate::query_error::QueryError;
use moon_config::{LanguageType, PlatformType, ProjectType, StackType, TaskType};
use moon_config::{LanguageType, ProjectType, StackType, TaskType};
use starbase_utils::glob::GlobSet;
use std::borrow::Cow;
use std::cmp::PartialEq;
Expand All @@ -21,7 +21,7 @@ pub enum Field<'l> {
ProjectType(Vec<ProjectType>),
Tag(FieldValues<'l>),
Task(FieldValues<'l>),
TaskPlatform(Vec<PlatformType>),
TaskPlatform(FieldValues<'l>),
TaskToolchain(FieldValues<'l>),
TaskType(Vec<TaskType>),
}
Expand Down Expand Up @@ -131,9 +131,8 @@ fn build_criteria(ast: Vec<AstNode<'_>>) -> miette::Result<Criteria<'_>> {
}
"tag" => Field::Tag(value),
"task" => Field::Task(value),
"taskPlatform" => Field::TaskPlatform(build_criteria_enum::<PlatformType>(
&field, &op, value,
)?),
"taskPlatform" => Field::TaskPlatform(value),
"taskToolchain" => Field::TaskToolchain(value),
"taskType" => {
Field::TaskType(build_criteria_enum::<TaskType>(&field, &op, value)?)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/query/tests/builder_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use moon_config::{LanguageType, PlatformType, ProjectType, StackType, TaskType};
use moon_config::{LanguageType, ProjectType, StackType, TaskType};
use moon_query::{
build_query, ComparisonOperator, Condition, Criteria, Field, FieldValues, LogicalOperator,
};
Expand Down Expand Up @@ -626,7 +626,7 @@ mod mql_build {
Criteria {
op: LogicalOperator::And,
conditions: vec![Condition::Field {
field: Field::TaskPlatform(vec![PlatformType::Node]),
field: Field::TaskPlatform(value_list(["node"])),
op: ComparisonOperator::Equal,
}],
input: Some("taskPlatform=node".into())
Expand All @@ -641,7 +641,7 @@ mod mql_build {
Criteria {
op: LogicalOperator::And,
conditions: vec![Condition::Field {
field: Field::TaskPlatform(vec![PlatformType::Node, PlatformType::System]),
field: Field::TaskPlatform(value_list(["node", "system"])),
op: ComparisonOperator::NotEqual,
}],
input: Some("taskPlatform!=[node, system]".into())
Expand Down
11 changes: 1 addition & 10 deletions crates/workspace-graph/src/query_projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,7 @@ impl WorkspaceGraph {
Field::Task(ids) => Ok(project.task_targets.iter().any(|target| {
condition.matches(ids, &target.task_id).unwrap_or_default()
})),
Field::TaskPlatform(platforms) => Ok(self
.tasks
.get_all_for_project(&project.id, false)?
.iter()
.any(|task| {
condition
.matches_enum(platforms, &task.platform)
.unwrap_or_default()
})),
Field::TaskToolchain(ids) => Ok(self
Field::TaskPlatform(ids) | Field::TaskToolchain(ids) => Ok(self
.tasks
.get_all_for_project(&project.id, false)?
.iter()
Expand Down
5 changes: 1 addition & 4 deletions crates/workspace-graph/src/query_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ fn does_task_match_criteria(task: &Task, query: &Criteria) -> miette::Result<boo
}
}
Field::Task(ids) => condition.matches(ids, &task.id),
Field::TaskPlatform(platforms) => {
condition.matches_enum(platforms, &task.platform)
}
Field::TaskToolchain(ids) => {
Field::TaskPlatform(ids) | Field::TaskToolchain(ids) => {
let toolchains = task
.toolchains
.iter()
Expand Down

0 comments on commit 3f1d634

Please sign in to comment.