add comments

This commit is contained in:
Moritz Hölting 2024-04-03 00:45:18 +02:00
parent e8f7ef9876
commit a1f948dfe3
2 changed files with 14 additions and 3 deletions

View File

@ -186,23 +186,31 @@ impl Execute {
command => command
.compile(options, global_state, function_state)
.into_iter()
.map(|c| (true, prefix.clone() + "run " + &c))
.map(|c| map_run_cmd(c, &prefix))
.collect(),
},
Self::Runs(commands) if !require_grouping => commands
.iter()
.flat_map(|c| c.compile(options, global_state, function_state))
.map(|c| (true, prefix.clone() + "run " + &c))
.map(|c| map_run_cmd(c, &prefix))
.collect(),
Self::Runs(commands) => Command::Group(commands.clone())
.compile(options, global_state, function_state)
.into_iter()
.map(|c| (true, prefix.clone() + "run " + &c))
.map(|c| map_run_cmd(c, &prefix))
.collect(),
}
}
}
fn map_run_cmd(cmd: String, prefix: &str) -> (bool, String) {
if cmd.starts_with('#') {
(false, cmd)
} else {
(true, prefix.to_string() + "run " + &cmd)
}
}
fn format_execute(
prefix: String,
new: &str,

View File

@ -22,6 +22,8 @@ pub enum Command {
Execute(Execute),
/// Group of commands to be called instantly after each other
Group(Vec<Command>),
/// Comment to be added to the function
Comment(String),
}
impl Command {
@ -42,6 +44,7 @@ impl Command {
Self::Debug(message) => compile_debug(message, options),
Self::Execute(ex) => ex.compile(options, global_state, function_state),
Self::Group(commands) => compile_group(commands, options, global_state, function_state),
Self::Comment(comment) => vec!["#".to_string() + comment],
}
}
}