context: copy symlinks as symlinks and improve error messages

This commit is contained in:
2026-07-17 10:12:46 +02:00
parent 2b27b7b06e
commit c4b59a4376
11 changed files with 383 additions and 55 deletions
+41 -7
View File
@@ -14,6 +14,17 @@ use log::{error, info};
mod ui;
/// Obtain the current working directory, exiting with a helpful message on failure.
fn current_dir_or_exit() -> std::path::PathBuf {
match std::env::current_dir() {
Ok(p) => p,
Err(e) => {
error!("Could not determine the current working directory: {}", e);
std::process::exit(1);
}
}
}
fn main() {
let rt = tokio::runtime::Runtime::new().unwrap();
let logger =
@@ -137,7 +148,7 @@ fn main() {
info!("Done.");
}
Some(("chlog", sub_matches)) => {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir_or_exit();
let version = sub_matches.get_one::<String>("version").map(|s| s.as_str());
if let Err(e) = generate_entry("debian/changelog", Some(&cwd), version) {
@@ -145,21 +156,38 @@ fn main() {
std::process::exit(1);
}
let editor = std::env::var("EDITOR").unwrap();
let _status = std::process::Command::new(editor)
let editor = match std::env::var("EDITOR") {
Ok(e) => e,
Err(_) => {
error!(
"No editor configured. Set the EDITOR environment variable \
(e.g. `EDITOR=nano` or `export EDITOR=vim`) and retry."
);
std::process::exit(1);
}
};
let _status = std::process::Command::new(&editor)
.current_dir(&cwd)
.args(["debian/changelog"])
.status();
.status()
.map_err(|e| {
error!(
"Could not launch editor '{}': {}. \
Make sure it is installed and available on PATH.",
editor, e
);
std::process::exit(1);
});
}
Some(("build", _sub_matches)) => {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir_or_exit();
if let Err(e) = pkh::build::build_source_package(Some(&cwd)) {
error!("{}", e);
std::process::exit(1);
}
}
Some(("deb", sub_matches)) => {
let cwd = std::env::current_dir().unwrap();
let cwd = current_dir_or_exit();
let series = sub_matches.get_one::<String>("series").map(|s| s.as_str());
let arch = sub_matches.get_one::<String>("arch").map(|s| s.as_str());
let cross = sub_matches.get_one::<bool>("cross").unwrap_or(&false);
@@ -221,7 +249,13 @@ fn main() {
"ssh" => {
let endpoint = args
.get_one::<String>("endpoint")
.expect("Endpoint is required for ssh context");
.unwrap_or_else(|| {
error!(
"An --endpoint is required to create an ssh context. \
Expected format: [ssh://][user@]host[:port]"
);
std::process::exit(1);
});
// Parse host, user, port from endpoint
// Formats: [ssh://][user@]host[:port]