Skip to content

Commit

Permalink
cmd: use a type alias to reduce the type complexity of get_command_en…
Browse files Browse the repository at this point in the history
…vironment()
  • Loading branch information
davvid committed Sep 28, 2024
1 parent 9af9392 commit d2c8f2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/cmds/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,11 @@ fn get_tree_from_context<'a>(
}

/// Prepare state needed for running commands.
#[allow(clippy::type_complexity)]
fn get_command_environment<'a>(
app_context: &'a model::ApplicationContext,
context: &model::TreeContext,
params: &CmdParams,
) -> Option<(Option<String>, &'a String, Vec<(String, String)>)> {
) -> Option<(Option<String>, &'a String, model::Environment)> {
let (config, tree) = get_tree_from_context(app_context, context, params)?;
// Trees must have a valid path available.
let Ok(tree_path) = tree.path_as_ref() else {
Expand Down Expand Up @@ -489,7 +488,7 @@ fn expand_and_run_command(
path: &str,
shell_params: &ShellParams,
params: &CmdParams,
env: &Vec<(String, String)>,
env: &model::Environment,
) -> Result<i32, i32> {
let mut exit_status = errors::EX_OK;
// Create a sequence of the command names to run including pre and post-commands.
Expand Down Expand Up @@ -706,7 +705,7 @@ fn run_cmd_depth_first_parallel(
fn run_cmd_vec(
path: &str,
shell_params: &ShellParams,
env: &Vec<(String, String)>,
env: &model::Environment,
cmd_seq_vec: &[Vec<String>],
params: &CmdParams,
) -> Result<(), i32> {
Expand Down
4 changes: 2 additions & 2 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ pub fn environment(
app_context: &model::ApplicationContext,
config: &model::Configuration,
context: &model::TreeContext,
) -> Vec<(String, String)> {
let mut result = Vec::new();
) -> model::Environment {
let mut result = model::Environment::new();
let mut vars = Vec::new();

// Evaluate environment variables defined at global scope.
Expand Down
3 changes: 3 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub type GraftName = String;
/// Configuration Node IDs
pub type ConfigId = NodeId;

/// Environment variables are set when running commands.
pub(crate) type Environment = Vec<(String, String)>;

/// Config files can define a sequence of variables that are
/// iteratively calculated. Variables can reference other
/// variables in their Tree, Garden, and Configuration scopes.
Expand Down

0 comments on commit d2c8f2a

Please sign in to comment.