aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/main.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-14 04:18:14 +0000
committertv <tv@krebsco.de>2026-11-14 04:18:14 +0000
commitee3a91eada2e863a192980df1f15dedd9f397f1c (patch)
tree56794bf9ea9635dedaafa63d89838f6e3d8b1a77 /pkgs/populate/src/main.rs
parenta9ad68526998290bf8203008d6db710727953d20 (diff)
populate: populate shell, running shell code on a target
populate shell [OPTION]... TARGET SCRIPT runs SCRIPT with /bin/sh on TARGET, reached like populate reaches it, deciding whether it's local when it runs, with local or remote as $1, so SCRIPT can tell. It takes populate's target options but --path, and --tty, giving SCRIPT a terminal on a remote target, and --local-only, failing before connecting unless the target is local. It replaces itself with the command running SCRIPT, so the exit status, the terminal, and signals are SCRIPT's. krops can run nixos-rebuild with it, which needs whether the target is local, unless it decides that during evaluation, which pure evaluation can't. The command line's parsing is shared between populate and populate shell.
Diffstat (limited to 'pkgs/populate/src/main.rs')
-rw-r--r--pkgs/populate/src/main.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/pkgs/populate/src/main.rs b/pkgs/populate/src/main.rs
index eeed1ef..684c515 100644
--- a/pkgs/populate/src/main.rs
+++ b/pkgs/populate/src/main.rs
@@ -1,6 +1,7 @@
//! populate [OPTION]... SOURCES [TARGET]: delivers the sources in the JSON
//! file SOURCES, or standard input for -, to the target directory TARGET.
-//! See README.md.
+//! populate shell [OPTION]... TARGET SCRIPT runs the shell code SCRIPT on
+//! TARGET. See README.md.
mod check;
mod cli;
@@ -10,6 +11,7 @@ mod populate;
mod rsync;
mod run;
mod sh;
+mod shell;
mod spec;
use std::io::Read;
@@ -22,8 +24,8 @@ const USAGE: u8 = 2;
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
let options = match cli::parse(&args) {
- Ok(cli::Command::Help) => {
- print!("{}", cli::USAGE);
+ Ok(cli::Command::Help(usage)) => {
+ print!("{usage}");
return ExitCode::SUCCESS;
}
Ok(cli::Command::Version) => {
@@ -31,16 +33,16 @@ fn main() -> ExitCode {
return ExitCode::SUCCESS;
}
Ok(cli::Command::Populate(options)) => options,
+ Ok(cli::Command::Shell(options)) => return shell::shell(options),
Err(message) => {
+ // The usage lines of the command the arguments are for.
+ let usage = if args.first().map(String::as_str) == Some("shell") {
+ cli::SHELL_USAGE.lines().take(1).collect::<Vec<_>>()
+ } else {
+ cli::USAGE.lines().take(2).collect::<Vec<_>>()
+ };
eprintln!("populate: {message}");
- eprint!(
- "{}",
- cli::USAGE
- .lines()
- .next()
- .map(|l| format!("{l}\n"))
- .unwrap_or_default()
- );
+ eprintln!("{}", usage.join("\n"));
return ExitCode::from(USAGE);
}
};