Skip to main content

flake_edit/app/commands/
config.rs

1//! `flake-edit config`: surface configuration without mutating the
2//! flake.
3//!
4//! `--print-default` writes the embedded default
5//! [`DEFAULT_CONFIG_TOML`] to stdout. `--path` reports the lookup
6//! locations for the project and user config files. With neither
7//! flag the subcommand is a no-op.
8
9use crate::config::{Config, DEFAULT_CONFIG_TOML};
10
11use super::Result;
12
13pub fn config(print_default: bool, path: bool) -> Result<()> {
14    if print_default {
15        print!("{}", DEFAULT_CONFIG_TOML);
16        return Ok(());
17    }
18
19    if path {
20        let project_path = Config::project_config_path();
21        let user_path = Config::user_config_path();
22
23        if let Some(path) = &project_path {
24            println!("Project config: {}", path.display());
25        }
26        if let Some(path) = &user_path {
27            println!("User config: {}", path.display());
28        }
29
30        if project_path.is_none() && user_path.is_none() {
31            if let Some(user_dir) = Config::user_config_dir() {
32                println!("No config found. Create one at:");
33                println!("  Project: flake-edit.toml (in current directory)");
34                println!("  User:    {}/config.toml", user_dir.display());
35            } else {
36                println!("No config found. Create flake-edit.toml in current directory.");
37            }
38        }
39        return Ok(());
40    }
41
42    Ok(())
43}