Skip to content

Commit

Permalink
syntax: add pre_command() and post_command() helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
davvid committed Dec 23, 2023
1 parent 63f4b7e commit 1bc4397
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::errors;
use super::eval;
use super::model;
use super::syntax;

/// Convert an exit status to Result<(), GardenError>.
pub(crate) fn result_from_exit_status(exit_status: i32) -> Result<(), errors::GardenError> {
Expand Down Expand Up @@ -231,8 +232,8 @@ pub(crate) fn expand_command_names(
context: &model::TreeContext,
name: &str,
) -> Vec<String> {
let pre_name = format!("{}<", name);
let post_name = format!("{}>", name);
let pre_name = syntax::pre_command(name);
let post_name = syntax::post_command(name);
let pre_commands = get_command_values(app_context, context, &pre_name);
let post_commands = get_command_values(app_context, context, &post_name);

Expand Down
12 changes: 12 additions & 0 deletions src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,15 @@ pub(crate) fn string_to_bool(value: &str) -> Option<bool> {
_ => None,
}
}

/// Add a pre-command suffix to a command name.
#[inline]
pub(crate) fn pre_command(name: &str) -> String {
format!("{}<", name)
}

/// Add a post-command suffix to a command name.
#[inline]
pub(crate) fn post_command(name: &str) -> String {
format!("{}>", name)
}

0 comments on commit 1bc4397

Please sign in to comment.