fix(cli): Don't silently overwrite existing config file

This commit is contained in:
Andrew Hlynskyi 2021-06-27 03:03:47 +03:00
parent 2b83500b74
commit 2e2b239c42
2 changed files with 7 additions and 1 deletions

View file

@ -20,7 +20,7 @@ pub struct Config {
}
impl Config {
fn find_config_file() -> Result<Option<PathBuf>> {
pub fn find_config_file() -> Result<Option<PathBuf>> {
if let Ok(path) = env::var("TREE_SITTER_DIR") {
let mut path = PathBuf::from(path);
path.push("config.json");

View file

@ -194,6 +194,12 @@ fn run() -> Result<()> {
match matches.subcommand() {
("init-config", Some(_)) => {
if let Ok(Some(config_path)) = Config::find_config_file() {
return Err(anyhow!(
"Remove your existing config file first: {}",
config_path.to_string_lossy()
));
}
let mut config = Config::initial()?;
config.add(tree_sitter_loader::Config::initial())?;
config.add(tree_sitter_cli::highlight::ThemeConfig::default())?;