summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-11-16 00:15:28 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-11-16 18:53:01 +0100
commitbd8479a1ebf3862c13909e270ddd6179d9a24591 (patch)
tree175e7c3955dd475742f0f6d8e662a767fc5ae309
parentc92e70120a69e81387cae616c4f3286d25666411 (diff)
downloadrebel-bd8479a1ebf3862c13909e270ddd6179d9a24591.tar
rebel-bd8479a1ebf3862c13909e270ddd6179d9a24591.zip
driver: parse: add support for + flag
The + flag will be used to force running a task.
-rw-r--r--crates/driver/src/context.rs2
-rw-r--r--crates/driver/src/parse.rs34
2 files changed, 30 insertions, 6 deletions
diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs
index b89b23c..3a40102 100644
--- a/crates/driver/src/context.rs
+++ b/crates/driver/src/context.rs
@@ -354,7 +354,7 @@ impl Context {
}
pub fn parse<'ctx>(&'ctx self, s: &str) -> error::Result<TaskRef> {
- let parsed = parse::parse_task(s).context("Invalid task syntax")?;
+ let (parsed, _flags) = parse::parse_task_with_flags(s).context("Invalid task syntax")?;
let recipe = parsed.recipe.to_string();
let task = parsed.task.to_string();
diff --git a/crates/driver/src/parse.rs b/crates/driver/src/parse.rs
index 892b654..aad9360 100644
--- a/crates/driver/src/parse.rs
+++ b/crates/driver/src/parse.rs
@@ -5,13 +5,19 @@ use nom::{
Err, IResult, InputLength, Parser,
};
-pub struct Output<'a> {
+#[derive(Debug, Clone, Copy)]
+pub struct Task<'a> {
pub recipe: &'a str,
pub task: &'a str,
pub host: Option<&'a str>,
pub target: Option<&'a str>,
}
+#[derive(Debug, Clone, Copy)]
+pub struct TaskFlags {
+ pub force_run: bool,
+}
+
fn is_name_char(c: char) -> bool {
matches!(c, 'a'..='z' | 'A' ..='Z' | '0'..='9' | '_' | '-')
}
@@ -41,7 +47,7 @@ fn task_args(input: &str) -> IResult<&str, (Option<&str>, Option<&str>)> {
Ok((input, (host, target)))
}
-fn task_ref(input: &str) -> IResult<&str, Output> {
+fn task(input: &str) -> IResult<&str, Task> {
let (input, (recipe, task)) = task_id(input)?;
let (input, args) = opt(task_args)(input)?;
@@ -49,7 +55,7 @@ fn task_ref(input: &str) -> IResult<&str, Output> {
Ok((
input,
- Output {
+ Task {
recipe,
task,
host,
@@ -58,6 +64,24 @@ fn task_ref(input: &str) -> IResult<&str, Output> {
))
}
+fn task_flags(input: &str) -> IResult<&str, TaskFlags> {
+ let (input, force_run) = opt(tag("+"))(input)?;
+
+ Ok((
+ input,
+ TaskFlags {
+ force_run: force_run.is_some(),
+ },
+ ))
+}
+
+fn task_with_flags(input: &str) -> IResult<&str, (Task, TaskFlags)> {
+ let (input, task) = task(input)?;
+ let (input, flags) = task_flags(input)?;
+
+ Ok((input, (task, flags)))
+}
+
fn parse_all<I, O, E: ParseError<I>, F>(f: F, input: I) -> Result<O, Err<E>>
where
I: InputLength,
@@ -66,6 +90,6 @@ where
all_consuming(f)(input).map(|(_, result)| result)
}
-pub fn parse_task(input: &str) -> Option<Output> {
- parse_all(task_ref, input).ok()
+pub fn parse_task_with_flags(input: &str) -> Option<(Task, TaskFlags)> {
+ parse_all(task_with_flags, input).ok()
}