#![allow(dead_code)]
use assert_cmd::Command;
use std::path::{Path, PathBuf};
pub fn aiseo_in(home: &Path) -> Command {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.env("HOME", home)
.env("XDG_CONFIG_HOME", home.join(".config"))
.env("XDG_DATA_HOME", home.join(".local/share"))
.env("XDG_CACHE_HOME", home.join(".cache"));
cmd
}
pub fn config_path_in(home: &Path) -> PathBuf {
let out = aiseo_in(home)
.args(["--json", "config", "path"])
.output()
.unwrap();
assert!(out.status.success());
let json: serde_json::Value =
serde_json::from_slice(&out.stdout).expect("config path should be JSON");
PathBuf::from(json["data"]["path"].as_str().unwrap())
}
pub fn write_config_in(home: &Path, contents: &str) -> PathBuf {
let path = config_path_in(home);
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, contents).unwrap();
path
}