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

Function cmd_migrate_config

src/main.rs:1084–1145  ·  view source on GitHub ↗
(
    config_path: &str,
    on_ambiguous: Option<OnAmbiguousOption>,
)

Source from the content-addressed store, hash-verified

1082}
1083
1084fn cmd_migrate_config(
1085 config_path: &str,
1086 on_ambiguous: Option<OnAmbiguousOption>,
1087) -> Result<(), Box<dyn std::error::Error>> {
1088 tui::print_banner("Migrate Config");
1089
1090 if !nix::unistd::getuid().is_root() {
1091 tui::print_callout(
1092 "Administrative Privileges Required",
1093 &[
1094 "Configuration migration updates protected files under /etc/clawshell.",
1095 "",
1096 "Please re-run with sudo:",
1097 "",
1098 &format!(" $ sudo clawshell migrate-config --config {config_path}"),
1099 ],
1100 );
1101 std::process::exit(1);
1102 }
1103
1104 let path = PathBuf::from(config_path);
1105 if !path.exists() {
1106 tui::print_error(&format!("Configuration file not found: {}", path.display()));
1107 std::process::exit(1);
1108 }
1109
1110 let targets: Vec<Box<dyn MigrationTarget>> = vec![Box::new(ClawshellTomlTarget::new(path))];
1111 let mut resolver: Box<dyn AmbiguityResolver> = match on_ambiguous {
1112 Some(OnAmbiguousOption::Fail) => Box::new(FailOnAmbiguousResolver),
1113 None => Box::new(InteractiveAmbiguityResolver),
1114 };
1115
1116 let report = orchestrator::migrate_targets(&targets, resolver.as_mut())?;
1117 tui::print_info("Target version", &report.to_version.to_string());
1118
1119 for target in report.targets {
1120 println!();
1121 tui::print_section(&format!("Target: {}", target.target_name));
1122 tui::print_info("File", &target.path.display().to_string());
1123 tui::print_info("From", &target.from_version.to_string());
1124 tui::print_info("To", &target.to_version.to_string());
1125 if target.changed {
1126 tui::print_success("Migration applied.");
1127 if let Some(backup) = target.backup_path {
1128 tui::print_info("Backup", &backup.display().to_string());
1129 }
1130 } else {
1131 tui::print_success("Already up to date.");
1132 }
1133
1134 for step in target.applied_steps {
1135 tui::print_info("Step", &step);
1136 }
1137 for warning in target.warnings {
1138 tui::print_warning(&warning);
1139 }
1140 }
1141

Callers 1

mainFunction · 0.85

Calls 8

print_bannerFunction · 0.85
print_calloutFunction · 0.85
print_errorFunction · 0.85
migrate_targetsFunction · 0.85
print_infoFunction · 0.85
print_sectionFunction · 0.85
print_successFunction · 0.85
print_warningFunction · 0.85

Tested by

no test coverage detected