ronantakizawa/codereview-bench huggingface dataset:
Repository: casey/just
File: tests/misc.rs (Rust)

Code before:

foo:
  /bin/echo '{{we}}'
"#,
  stdout:   "",
  stderr:   format!("{} {}\n{}\n{}\n{}\n",
    "error: Call to function `parent_directory` failed:",
    "Cannot get parent directory from ``",
    "  |",
    "1 | we  := parent_directory(\'\')",
    "  |        ^^^^^^^^^^^^^^^^").as_str(),
  status:   EXIT_FAILURE,
}

#[cfg(not(windows))]
test! {
  name: broken_directory_function2,
  justfile: r#"
we  := parent_directory('/')

foo:
  /bin/echo '{{we}}'
"#,
  stdout:   "",
  stderr:   format!("{}\n{}\n{}\n{}\n",
    "error: Call to function `parent_directory` failed: Cannot get parent directory from `/`",
    "  |",
    "1 | we  := parent_directory(\'/\')",
    "  |        ^^^^^^^^^^^^^^^^").as_str(),
  status:   EXIT_FAILURE,
}

#[cfg(windows)]
test! {
  name:     env_var_functions,
  justfile: r#"
p := env_var('USERNAME')
b := env_var_or_default('ZADDY', 'HTAP')
x := env_var_or_default('XYZ', 'ABC')

foo:
  /bin/echo '{{p}}' '{{b}}' '{{x}}'
"#,
  stdout:   format!("{} HTAP ABC\n", env::var("USERNAME").unwrap()).as_str(),
  stderr:   format!("/bin/echo '{}' 'HTAP' 'ABC'\n", env::var("USERNAME").unwrap()).as_str(),
}

test! {
  name:     env_var_failure,
  justfile: "a:\n  echo {{env_var('ZADDY')}}",
  args:     ("a"),

Review comment (bug):
```suggestion
    "error: Call to function `parent_directory` failed: Could not extract parent directory from `/`",
```

Code after:

foo:
  /bin/echo '{{we}}'
"#,
  stdout:   "",
  stderr:   format!("{} {}\n{}\n{}\n{}\n",
    "error: Call to function `parent_directory` failed:",
    "Could not extract parent directory from ``",
    "  |",
    "1 | we  := parent_directory(\'\')",
    "  |        ^^^^^^^^^^^^^^^^").as_str(),
  status:   EXIT_FAILURE,
}

#[cfg(not(windows))]
test! {
  name: broken_directory_function2,
  justfile: r#"
we  := parent_directory('/')

foo:
  /bin/echo '{{we}}'
"#,
  stdout:   "",
  stderr:   format!("{} {}\n{}\n{}\n{}\n",
    "error: Call to function `parent_directory` failed:",
    "Could not extract parent directory from `/`",
    "  |",
    "1 | we  := parent_directory(\'/\')",
    "  |        ^^^^^^^^^^^^^^^^").as_str(),
  status:   EXIT_FAILURE,
}

#[cfg(windows)]
test! {
  name:     env_var_functions,
  justfile: r#"
p := env_var('USERNAME')
b := env_var_or_default('ZADDY', 'HTAP')
x := env_var_or_default('XYZ', 'ABC')

foo:
  /bin/echo '{{p}}' '{{b}}' '{{x}}'
"#,
  stdout:   format!("{} HTAP ABC\n", env::var("USERNAME").unwrap()).as_str(),
  stderr:   format!("/bin/echo '{}' 'HTAP' 'ABC'\n", env::var("USERNAME").unwrap()).as_str(),
}

test! {
  name:     env_var_failure,
  justfile: "a:\n  echo {{env_var('ZADDY')}}",
Repository: casey/just
File: src/load_dotenv.rs (Rust)

Code before:
use crate::common::*;

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if settings.dotenv_load.is_none()
    && config.verbosity.loud()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
      .map(|val| val.as_os_str().to_str() == Some("1"))
      .unwrap_or(false)
  {
    eprintln!(
      "{}",
      Warning::DotenvLoad.color_display(config.color.stderr())
    );
  }

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
    let (key, value) = result?;
    if env::var_os(&key).is_none() {
      dotenv.insert(key, value);
    }
  }
  Ok(dotenv)
}

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,

Review comment (suggestion):
This warning concerns implicit loading of `.env` files, as some future version of `just` will switch from loading `.env` files automatically to only on request.

If the user passes either `--dotenv-path` or `--dotenv-filename`, then this warning shouldn't be printed, since they explicitly requested that an environment file be loaded.

Code after:
use crate::common::*;

const DEFAULT_DOTENV_FILENAME: &str = ".env";

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true)
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
  {
    return Ok(BTreeMap::new());
  }

  if let Some(path) = &config.dotenv_path {
    return load_from_file(config, settings, &path);
  }

  let filename = config
    .dotenv_filename
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
Repository: casey/just
File: src/load_dotenv.rs (Rust)

Code before:

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
    let (key, value) = result?;
    if env::var_os(&key).is_none() {
      dotenv.insert(key, value);
    }
  }
  Ok(dotenv)
}

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true) {
    return Ok(BTreeMap::new());
  }

  // look directly for the environment file if specified by path
  let path = working_directory.join(&config.dotenv_path);
  if path.is_file() {
    return load_from_file(config, settings, &path);
  }

  // search upward for the environment file if specified by filename
  for directory in working_directory.ancestors() {
    let path = directory.join(&config.dotenv_filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}


Review comment (suggestion):
This should return an error if the user passed `--dotenv-path` and the file cannot be loaded, which we can do if we just unconditionally load the file when the flag is passed:

```suggestion
  if let Some(dotenv_path) = &config.dotenv_path {
    return load_from_file(config, settings, &dotenv_path);
  }
```

I don't think we need to do `working_directory.join(&config.dotenv_path)`, since file reads are always done relative to the current working directory.

Code after:
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if config.verbosity.loud()
    && settings.dotenv_load.is_none()
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
      .map(|val| val.as_os_str().to_str() == Some("1"))
      .unwrap_or(false)
  {
    eprintln!(
      "{}",
      Warning::DotenvLoad.color_display(config.color.stderr())
    );
  }

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
    let (key, value) = result?;
    if env::var_os(&key).is_none() {
      dotenv.insert(key, value);
    }
  }
  Ok(dotenv)
}
Repository: casey/just
File: src/load_dotenv.rs (Rust)

Code before:
  if settings.dotenv_load.is_none()
    && config.verbosity.loud()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
      .map(|val| val.as_os_str().to_str() == Some("1"))
      .unwrap_or(false)
  {
    eprintln!(
      "{}",
      Warning::DotenvLoad.color_display(config.color.stderr())
    );
  }

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
    let (key, value) = result?;
    if env::var_os(&key).is_none() {
      dotenv.insert(key, value);
    }
  }
  Ok(dotenv)
}

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true) {
    return Ok(BTreeMap::new());
  }

  // look directly for the environment file if specified by path
  let path = working_directory.join(&config.dotenv_path);
  if path.is_file() {
    return load_from_file(config, settings, &path);
  }

  // search upward for the environment file if specified by filename
  for directory in working_directory.ancestors() {
    let path = directory.join(&config.dotenv_filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}


Review comment (refactor):
Let's move this function after `load_dotenv` in the file, since it's always called afterwards.

Code after:
    && config.dotenv_path.is_none()
  {
    return Ok(BTreeMap::new());
  }

  if let Some(path) = &config.dotenv_path {
    return load_from_file(config, settings, &path);
  }

  let filename = config
    .dotenv_filename
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if config.verbosity.loud()
    && settings.dotenv_load.is_none()
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
      .map(|val| val.as_os_str().to_str() == Some("1"))
      .unwrap_or(false)
  {
    eprintln!(
      "{}",
      Warning::DotenvLoad.color_display(config.color.stderr())
    );
  }

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
Repository: casey/just
File: src/load_dotenv.rs (Rust)

Code before:
use crate::common::*;

const DEFAULT_DOTENV_FILENAME: &str = ".env";

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true) {
    return Ok(BTreeMap::new());
  }

  if let Some(path) = &config.dotenv_path {
    return load_from_file(config, settings, &path);
  }

  let filename = match &config.dotenv_filename {
    Some(name) => name,
    None => DEFAULT_DOTENV_FILENAME,
  };

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if settings.dotenv_load.is_none()
    && config.verbosity.loud()
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")

Review comment (suggestion):
Can this be something like:

```suggestion
  let filename = config.dotenv_filename.unwrap_or(DEFAULT_DOTENV_FILENAME);
```

Might need to juggle the types a little bit to get it to work.

Code after:
use crate::common::*;

const DEFAULT_DOTENV_FILENAME: &str = ".env";

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true)
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
  {
    return Ok(BTreeMap::new());
  }

  if let Some(path) = &config.dotenv_path {
    return load_from_file(config, settings, &path);
  }

  let filename = config
    .dotenv_filename
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if config.verbosity.loud()
Repository: casey/just
File: src/load_dotenv.rs (Rust)

Code before:
  };

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if settings.dotenv_load.is_none()
    && config.verbosity.loud()
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
      .map(|val| val.as_os_str().to_str() == Some("1"))
      .unwrap_or(false)
  {
    eprintln!(
      "{}",
      Warning::DotenvLoad.color_display(config.color.stderr())
    );
  }

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
    let (key, value) = result?;
    if env::var_os(&key).is_none() {
      dotenv.insert(key, value);
    }
  }
  Ok(dotenv)
}


Review comment (suggestion):
```suggestion
  if config.verbosity.loud()
    && settings.dotenv_load.is_none()
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
```

Code after:
  let filename = config
    .dotenv_filename
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,
  settings: &Settings,
  path: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  // `dotenv::from_path_iter` should eventually be un-deprecated, see:
  // https://github.com/dotenv-rs/dotenv/issues/13
  #![allow(deprecated)]

  if config.verbosity.loud()
    && settings.dotenv_load.is_none()
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
    && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING")
      .map(|val| val.as_os_str().to_str() == Some("1"))
      .unwrap_or(false)
  {
    eprintln!(
      "{}",
      Warning::DotenvLoad.color_display(config.color.stderr())
    );
  }

  let iter = dotenv::from_path_iter(&path)?;
  let mut dotenv = BTreeMap::new();
  for result in iter {
    let (key, value) = result?;
    if env::var_os(&key).is_none() {
      dotenv.insert(key, value);
    }
  }
  Ok(dotenv)
}
Repository: casey/just
File: tests/dotenv.rs (Rust)

Code before:
       this warning and stop loading `.env` files, add:

    set dotenv-load := false

This warning may \
       also be silenced by setting the `JUST_SUPPRESS_DOTENV_LOAD_WARNING`
environment variable to `1`. \
       This can be used to silence the warning globally by
adding the following line to your shell rc \
       file:

  export JUST_SUPPRESS_DOTENV_LOAD_WARNING=1

See https://github.com/casey/just/issues/469 \
       for more details.
echo $DOTENV_KEY
   ",
    )
    .suppress_dotenv_load_warning(false)
    .run();
}

#[test]
fn path_not_found() {
  Test::new()
    .justfile("foo:\n\techo $NAME")
    .args(&["--dotenv-path", ".env.prod"])
    .stderr(if cfg!(windows) {
      "error: Failed to load environment file: The system cannot find the file specified. (os \
       error 2)\n"
    } else {
      "error: Failed to load environment file: No such file or directory (os error 2)\n"
    })
    .status(EXIT_FAILURE)
    .run();
}

#[test]
fn path_resolves() {
  Test::new()
    .justfile("foo:\n\t#!/bin/bash\n\techo $NAME")
    .tree(tree! {
      subdir: {
        ".env": "NAME=bar"
      }
    })
    .args(&["--dotenv-path", "subdir/.env"])
    .stdout("bar\n")
    .status(EXIT_SUCCESS)
    .run();
}

Review comment (suggestion):
The argument to `Test::justfile` is passed to `unindent`, so you can write it like this:

```suggestion
    .justfile("
      foo:
        echo $NAME
    ")
```

Code after:
       this warning and stop loading `.env` files, add:

    set dotenv-load := false

This warning may \
       also be silenced by setting the `JUST_SUPPRESS_DOTENV_LOAD_WARNING`
environment variable to `1`. \
       This can be used to silence the warning globally by
adding the following line to your shell rc \
       file:

  export JUST_SUPPRESS_DOTENV_LOAD_WARNING=1

See https://github.com/casey/just/issues/469 \
       for more details.
echo $DOTENV_KEY
   ",
    )
    .suppress_dotenv_load_warning(false)
    .run();
}

#[test]
fn path_not_found() {
  Test::new()
    .justfile(
      "
      foo:
        echo $NAME
    ",
    )
    .args(&["--dotenv-path", ".env.prod"])
    .stderr(if cfg!(windows) {
      "error: Failed to load environment file: The system cannot find the file specified. (os \
       error 2)\n"
    } else {
      "error: Failed to load environment file: No such file or directory (os error 2)\n"
    })
    .status(EXIT_FAILURE)
    .run();
}

#[test]
fn path_resolves() {
  Test::new()
    .justfile(
      "
      foo:
        @echo $NAME
    ",
    )
Repository: casey/just
File: src/load_dotenv.rs (Rust)

Code before:
use crate::common::*;

const DEFAULT_DOTENV_FILENAME: &str = ".env";

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true) {
    return Ok(BTreeMap::new());
  }

  if let Some(path) = &config.dotenv_path {
    return load_from_file(config, settings, &path);
  }

  let filename = config
    .dotenv_filename
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}

fn load_from_file(
  config: &Config,

Review comment (suggestion):
Okay, last thing I swear. I just realized that if the user is passing `--dotenv-path` or `--dotenv-filename`, that should probably override `set dotenv-load := false`.

So this should be something like:

```suggestion
  if !settings.dotenv_load.unwrap_or(true) && config.dotenv_filename.is_none() && config.dotenv_path.is_none() {
```

This should also have tests for both cases, if you have a justfile with `set dotenv-load := false`, passing either flag causes an environment file to be loaded.

Code after:
use crate::common::*;

const DEFAULT_DOTENV_FILENAME: &str = ".env";

pub(crate) fn load_dotenv(
  config: &Config,
  settings: &Settings,
  working_directory: &Path,
) -> RunResult<'static, BTreeMap<String, String>> {
  if !settings.dotenv_load.unwrap_or(true)
    && config.dotenv_filename.is_none()
    && config.dotenv_path.is_none()
  {
    return Ok(BTreeMap::new());
  }

  if let Some(path) = &config.dotenv_path {
    return load_from_file(config, settings, &path);
  }

  let filename = config
    .dotenv_filename
    .as_deref()
    .unwrap_or(DEFAULT_DOTENV_FILENAME)
    .to_owned();

  for directory in working_directory.ancestors() {
    let path = directory.join(&filename);
    if path.is_file() {
      return load_from_file(config, settings, &path);
    }
  }

  Ok(BTreeMap::new())
}
Repository: casey/just
File: src/subcommand.rs (Rust)

Code before:
      Ok(status) => status,
    };

    if !status.success() {
      return Err(Error::EditorStatus { editor, status });
    }

    Ok(())
  }

  fn format(config: &Config, ast: Ast, search: &Search) -> Result<(), Error<'static>> {
    config.require_unstable("The `--fmt` command is currently unstable.")?;

    if config.dry_run {
      use std::io::Read as _;
      let mut current_content = String::new();
      let mut file = File::open(&search.justfile).map_err(|e| Error::Load {
        path: search.justfile.clone(),
        io_error: e,
      })?;
      file
        .read_to_string(&mut current_content)
        .map_err(|e| Error::Load {
          path: search.justfile.clone(),
          io_error: e,
        })?;

      if current_content != format!("{}", ast) {
        Err(Error::NotWellFormatted {
          justfile: search.justfile.clone(),
        })
      } else {
        if config.verbosity.loud() {
          eprintln!("Justfile `{}` is well-formatted.", search.justfile.display());
        }
        Ok(())
      }
    } else if let Err(io_error) =
      File::create(&search.justfile).and_then(|mut file| write!(file, "{}", ast))
    {
      Err(Error::WriteJustfile {
        justfile: search.justfile.clone(),
        io_error,
      })
    } else {
      if config.verbosity.loud() {
        eprintln!("Wrote justfile to `{}`", search.justfile.display());
      }
      Ok(())
    }
  }

Review comment (suggestion):
The `src` can be passed in from outside, so we can avoid loading the file twice.

Code after:
      Ok(status) => status,
    };

    if !status.success() {
      return Err(Error::EditorStatus { editor, status });
    }

    Ok(())
  }

  fn format(config: &Config, ast: Ast, src: &str, search: &Search) -> Result<(), Error<'static>> {
    config.require_unstable("The `--fmt` command is currently unstable.")?;

    let src_formatted = ast.to_string();
    if config.check {
      if src == src_formatted {
        Ok(())
      } else {
        print!(
          "{}",
          similar::udiff::unified_diff(similar::Algorithm::Patience, &src, &src_formatted, 2, None)
        );
        Err(Error::FormatCheckFoundDiff)
      }
    } else if let Err(io_error) =
      File::create(&search.justfile).and_then(|mut file| file.write_all(&src_formatted.as_bytes()))
    {
      Err(Error::WriteJustfile {
        justfile: search.justfile.clone(),
        io_error,
      })
    } else {
      if config.verbosity.loud() {
        eprintln!("Wrote justfile to `{}`", search.justfile.display());
      }
      Ok(())
    }
  }

  fn init(config: &Config) -> Result<(), Error<'static>> {
    let search = Search::init(&config.search_config, &config.invocation_directory)?;

    if search.justfile.is_file() {
      Err(Error::InitExists {
        justfile: search.justfile,
      })
    } else if let Err(io_error) = fs::write(&search.justfile, INIT_JUSTFILE) {
      Err(Error::WriteJustfile {
        justfile: search.justfile,
        io_error,
      })