Skip to content

Commit

Permalink
garden: reduce visibility and eliminate dead code
Browse files Browse the repository at this point in the history
Use pub(crate) to reduce the surface area of exposed symbols.
  • Loading branch information
davvid committed Dec 22, 2023
1 parent df264c3 commit 5b48028
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl MainOptions {
}

/// Parse a vector of debug level arguments to count how many have been set
pub fn debug_level(debug: &[String], name: &str) -> u8 {
fn debug_level(debug: &[String], name: &str) -> u8 {
debug.iter().filter(|&x| x == name).count() as u8
}

Expand Down
12 changes: 4 additions & 8 deletions src/cmds/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ pub fn main_custom(app_context: &model::ApplicationContext, arguments: &Vec<Stri
/// If the names resolve to trees, each tree is processed independently
/// with no garden context.
pub fn cmd(
app_context: &model::ApplicationContext,
query: &str,
params: &CmdParams,
) -> Result<i32> {
fn cmd(app_context: &model::ApplicationContext, query: &str, params: &CmdParams) -> Result<i32> {
// Mutable scope for app.get_root_config_mut()
let config = app_context.get_root_config_mut();
// Resolve the tree query into a vector of tree contexts.
Expand All @@ -191,7 +187,7 @@ pub fn cmd(
}
}

pub fn run_cmd_breadth_first(
fn run_cmd_breadth_first(
app_context: &model::ApplicationContext,
contexts: &[model::TreeContext],
params: &CmdParams,
Expand Down Expand Up @@ -256,7 +252,7 @@ pub fn run_cmd_breadth_first(
Ok(exit_status)
}

pub fn run_cmd_depth_first(
fn run_cmd_depth_first(
app_context: &model::ApplicationContext,
contexts: &[model::TreeContext],
params: &CmdParams,
Expand Down Expand Up @@ -382,7 +378,7 @@ fn run_cmd_vec(
}

/// Run cmd() over a Vec of tree queries
pub fn cmds(app: &model::ApplicationContext, params: &CmdParams) -> Result<()> {
fn cmds(app: &model::ApplicationContext, params: &CmdParams) -> Result<()> {
let mut exit_status = errors::EX_OK;

for query in &params.queries {
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn main(app_context: &model::ApplicationContext, exec_options: &ExecOptions)
}

/// Execute a command over every tree in the evaluated tree query.
pub fn exec(
fn exec(
app_context: &model::ApplicationContext,
config: &model::Configuration,
quiet: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/grow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn main(app: &model::ApplicationContext, options: &GrowOptions) -> Result<()
}

/// Create/update trees in the evaluated tree query.
pub fn grow(
fn grow(
app_context: &model::ApplicationContext,
configured_worktrees: &mut HashSet<String>,
quiet: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main(app_context: &model::ApplicationContext, options: &mut InspectOption
}

/// Inspect every tree in the evaluated tree query
pub fn inspect(
fn inspect(
app_context: &model::ApplicationContext,
config: &model::Configuration,
verbose: u8,
Expand Down
4 changes: 2 additions & 2 deletions src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

/// Update a IndexSet "a" with the values from "b"
#[inline]
pub fn append_indexset<T>(a: &mut IndexSet<T>, b: &IndexSet<T>)
pub(crate) fn append_indexset<T>(a: &mut IndexSet<T>, b: &IndexSet<T>)
where
T: Clone + Eq + Ord + std::hash::Hash,
{
Expand All @@ -15,7 +15,7 @@ where

/// Update a Hashmap "a" with the values from "b".
#[inline]
pub fn append_hashmap<K, V>(a: &mut HashMap<K, V>, b: &HashMap<K, V>)
pub(crate) fn append_hashmap<K, V>(a: &mut HashMap<K, V>, b: &HashMap<K, V>)
where
K: Clone + Eq + Ord + std::hash::Hash,
V: Clone,
Expand Down
15 changes: 3 additions & 12 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ fn expand_tree_vars(
Some(String::new())
}

/// Expand variables using a tree context.
fn _expand_tree_context_vars(
_app: &model::ApplicationContext,
_tree_context: &model::TreeContext,
_name: &str,
) -> Result<Option<String>, String> {
Ok(None)
}

/// Expand variables at global scope only
fn expand_vars(
app_context: &model::ApplicationContext,
Expand Down Expand Up @@ -237,7 +228,7 @@ pub fn tree_value(

/// Resolve an expression in a garden/tree/global scope for execution by a shell.
/// This is used to generate the commands used internally by garden.
pub fn tree_value_for_shell(
fn tree_value_for_shell(
app_context: &model::ApplicationContext,
config: &model::Configuration,
expr: &str,
Expand Down Expand Up @@ -292,7 +283,7 @@ pub fn value(

/// Evaluate `$ <command>` command strings, AKA "exec expressions".
/// The result of the expression is the stdout output from the command.
pub fn exec_expression(string: &str, pathbuf: Option<std::path::PathBuf>) -> String {
fn exec_expression(string: &str, pathbuf: Option<std::path::PathBuf>) -> String {
let cmd = syntax::trim_exec(string);
let mut proc = subprocess::Exec::shell(cmd);
// Run the exec expression inside the tree's directory when specified.
Expand Down Expand Up @@ -337,7 +328,7 @@ pub fn multi_variable(
}

/// Evaluate a variable in the given context for execution in a shell
pub fn variables_for_shell(
fn variables_for_shell(
app_context: &model::ApplicationContext,
config: &model::Configuration,
variables: &mut Vec<model::Variable>,
Expand Down
2 changes: 1 addition & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn branches(path: &std::path::Path) -> Vec<String> {
}

/// Return the current branch name for the specified repository path.
pub fn branch(path: &std::path::Path) -> Option<String> {
pub(crate) fn branch(path: &std::path::Path) -> Option<String> {
let cmd = ["git", "symbolic-ref", "--quiet", "--short", "HEAD"];
let exec = cmd::exec_in_dir(&cmd, &path);
if let Ok(output) = cmd::stdout_to_string(exec) {
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
///
/// Parameters:
/// - `args`: A `std::fmt::Arguments`
pub fn error(args: std::fmt::Arguments) {
pub(crate) fn error(args: std::fmt::Arguments) {
eprintln!("error: {args}");
}

/// Print a message to stderr with a "debug: " prefix
///
/// Parameters:
/// - `args`: A `std::fmt::Arguments`
pub fn debug(args: std::fmt::Arguments) {
pub(crate) fn debug(args: std::fmt::Arguments) {
eprintln!("debug: {args}");
}

Expand Down
Loading

0 comments on commit 5b48028

Please sign in to comment.