Skip to content

Commit

Permalink
Simplify module_file and module_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 11, 2024
1 parent 93c9718 commit 8ef0823
Showing 1 changed file with 14 additions and 41 deletions.
55 changes: 14 additions & 41 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,50 +447,23 @@ fn lowercase(_context: Context, s: &str) -> FunctionResult {
}

fn module_directory(context: Context) -> FunctionResult {
context
.evaluator
.context
.search
.justfile
.parent()
.unwrap()
.join(&context.evaluator.context.module.source)
.parent()
.unwrap()
.to_str()
.map(str::to_owned)
.ok_or_else(|| {
format!(
"Module directory is not valid unicode: {}",
context
.evaluator
.context
.module
.source
.parent()
.unwrap()
.display(),
)
})
let module_directory = context.evaluator.context.module.source.parent().unwrap();
module_directory.to_str().map(str::to_owned).ok_or_else(|| {
format!(
"Module directory is not valid unicode: {}",
module_directory.display(),
)
})
}

fn module_file(context: Context) -> FunctionResult {
context
.evaluator
.context
.search
.justfile
.parent()
.unwrap()
.join(&context.evaluator.context.module.source)
.to_str()
.map(str::to_owned)
.ok_or_else(|| {
format!(
"Module file path is not valid unicode: {}",
context.evaluator.context.module.source.display(),
)
})
let module_file = &context.evaluator.context.module.source;
module_file.to_str().map(str::to_owned).ok_or_else(|| {
format!(
"Module file path is not valid unicode: {}",
module_file.display(),
)
})
}

fn num_cpus(_context: Context) -> FunctionResult {
Expand Down

0 comments on commit 8ef0823

Please sign in to comment.