Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed May 16, 2024
1 parent d7b78e7 commit b0c4c2e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3188,8 +3188,8 @@ below. You can put recipes that are used across many projects in this global
justfile, and easily invoke them from any directory.

`just` will search for a global justfile in the following locations, in this order, stopping after it finds a `justfile` in any location:
- `$XDG_CONFIG_HOME/just/global.just`
- `$HOME/.config/just/global.just`
- `$XDG_CONFIG_HOME/just/justfile`
- `$HOME/.config/just/justfile`
- `$HOME/.justfile`
- `$HOME/justfile`

Expand Down
16 changes: 5 additions & 11 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ pub(crate) struct Search {

impl Search {
fn candidate_global_justfiles() -> Vec<PathBuf> {
// Just will search for a global justfile in `$XDG_CONFIG_HOME/just/global.just`,
// `$HOME/.justfile`, `$HOME/justfile`, in that order.
// Just will search for a global justfile in `$XDG_CONFIG_HOME/just/justfile`,
// `$HOME/.config/just/justfile`, `$HOME/.justfile`, `$HOME/justfile`, in that order.
let mut global_candidate_paths = vec![];

// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
let xdg_config_home = if let Ok(config_dir) = std::env::var("XDG_CONFIG_HOME") {
Some(PathBuf::from(config_dir))
} else {
dirs::home_dir().map(|home_dir| home_dir.join(".config"))
};

if let Some(config_dir) = xdg_config_home {
global_candidate_paths.push(config_dir.join("just").join("global.just"));
let config_dir = dirs::config_dir().or_else(|| dirs::home_dir().map(|d| d.join(".config")));
if let Some(config_dir) = config_dir {
global_candidate_paths.push(config_dir.join("just").join(JUSTFILE_NAMES[0]));
}

if let Some(home_dir) = dirs::home_dir() {
Expand Down
40 changes: 40 additions & 0 deletions tests/global.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use super::*;

#[test]
fn test_global_justfile() {
let tmp = temptree! {
just: {
justfile: "default:\n echo 'foo'",

}
};

let xdg_config_path = tmp.path();

let output = Command::new(executable_path("just"))
.env("XDG_CONFIG_HOME", xdg_config_path.display().to_string())
.args(["--global"])
.output()
.expect("just invocation failed");

let expected_status = 0;
let expected_stdout = "foo\n";

let mut failure = false;

let status = output.status.code().unwrap();
if status != expected_status {
println!("bad status: {status} != {expected_status}");
failure = true;
}

let stdout = str::from_utf8(&output.stdout).unwrap();
if stdout != expected_stdout {
println!("bad stdout:\ngot:\n{stdout:?}\n\nexpected:\n{expected_stdout:?}");
failure = true;
}

if failure {
panic!("test failed");
}
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ mod export;
mod fallback;
mod fmt;
mod functions;
mod global;
mod ignore_comments;
mod imports;
mod init;
Expand Down

0 comments on commit b0c4c2e

Please sign in to comment.