MCPcopy Create free account
hub / github.com/clawshell/clawshell / cmd_config

Function cmd_config

src/main.rs:931–1082  ·  view source on GitHub ↗
(config_path: &str, edit: bool)

Source from the content-addressed store, hash-verified

929}
930
931fn cmd_config(config_path: &str, edit: bool) -> Result<(), Box<dyn std::error::Error>> {
932 tui::print_banner("Configuration");
933
934 let path = PathBuf::from(config_path);
935
936 if edit {
937 if !path.exists() {
938 tui::print_error(&format!("Configuration file not found: {config_path}"));
939 std::process::exit(1);
940 }
941
942 ensure_config_migrated(&path)?;
943
944 // Open in editor
945 let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
946
947 // Validate before editing to show current state
948 if path.exists()
949 && let Err(e) = Config::from_file(&path)
950 {
951 tui::print_warning(&format!("Current configuration has errors: {e}"));
952 }
953
954 let status = std::process::Command::new(&editor)
955 .arg(config_path)
956 .status()?;
957
958 if !status.success() {
959 tui::print_error("Editor exited with non-zero status.");
960 return Ok(());
961 }
962
963 // Validate after editing
964 match Config::from_file(&path) {
965 Ok(config) => {
966 tui::print_success("Configuration is valid.");
967 tui::print_info("Server", &config.listen_addr());
968 tui::print_info("Keys", &config.keys.len().to_string());
969 tui::print_info("DLP patterns", &config.dlp.patterns.len().to_string());
970 tui::print_warning(
971 "Changes will take effect after restarting ClawShell (clawshell restart).",
972 );
973 }
974 Err(e) => {
975 tui::print_error(&format!("Configuration validation failed: {e}"));
976 tui::print_warning("Please fix the errors before restarting ClawShell.");
977 }
978 }
979
980 return Ok(());
981 }
982
983 // Display mode
984 if !path.exists() {
985 tui::print_error(&format!("Configuration file not found: {config_path}"));
986 tui::print_warning(&format!(
987 "Run 'clawshell config --edit -f {}' to create one.",
988 config_path

Callers 1

mainFunction · 0.85

Calls 10

print_bannerFunction · 0.85
print_errorFunction · 0.85
ensure_config_migratedFunction · 0.85
print_warningFunction · 0.85
print_successFunction · 0.85
print_infoFunction · 0.85
version_gate_statusFunction · 0.85
print_migration_statusFunction · 0.85
print_sectionFunction · 0.85
listen_addrMethod · 0.80

Tested by

no test coverage detected