summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/fu/fupdate-sys2/src/cli.rs
diff options
context:
space:
mode:
authorSoispha Peetz <soispha@b-peetz.de>2026-12-03 23:12:40 +0100
committerSoispha Peetz <soispha@b-peetz.de>2026-12-03 23:19:04 +0100
commit605f131560a65af3448f02fb3990c1967ad488d0 (patch)
tree784938bd4532b8199b927adb41fc840da493940c /pkgs/by-name/fu/fupdate-sys2/src/cli.rs
parentpkgs/rollup: Also check if the `owner`'s tree is dirty in the general check (diff)
downloadnixos-config-605f131560a65af3448f02fb3990c1967ad488d0.zip
pkgs/fupdate-sys2: Re-implement in rust
Does not yet remove the shell version, because I'm not fully sure the rust version works. The rust version should also set the new boot entry forever, and not just for exactly one boot.
Diffstat (limited to 'pkgs/by-name/fu/fupdate-sys2/src/cli.rs')
-rw-r--r--pkgs/by-name/fu/fupdate-sys2/src/cli.rs84
1 files changed, 84 insertions, 0 deletions
diff --git a/pkgs/by-name/fu/fupdate-sys2/src/cli.rs b/pkgs/by-name/fu/fupdate-sys2/src/cli.rs
new file mode 100644
index 00000000..cf8a796e
--- /dev/null
+++ b/pkgs/by-name/fu/fupdate-sys2/src/cli.rs
@@ -0,0 +1,84 @@
+// nixos-config - My current NixOS configuration
+//
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of my nixos-config.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+use core::fmt;
+use std::{ffi::OsStr, process::Command};
+
+use clap::{Parser, ValueEnum};
+use clap_complete::{CompletionCandidate, engine::ArgValueCompleter};
+
+/// This is a Nix flake update manager.
+#[derive(Parser, Debug)]
+#[command(author, version, about)]
+pub struct CliArgs {
+ /// The branch to update from.
+ #[arg(short, long, add = ArgValueCompleter::new(get_branches))]
+ pub branch: Option<String>,
+
+ /// The mode to update with.
+ #[arg(short, long, default_value_t = Mode::Switch)]
+ pub mode: Mode,
+
+ /// Don't actually make changes.
+ #[arg(short, long)]
+ pub dry_run: bool,
+}
+
+#[derive(Debug, Clone, Copy, ValueEnum)]
+pub enum Mode {
+ Switch,
+ Boot,
+ Test,
+ Build,
+ DryBuild,
+ DryActivate,
+ Edit,
+ Repl,
+ BuildVm,
+ BuildVmWithBootloader,
+}
+
+impl fmt::Display for Mode {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", format!("{self:?}").to_lowercase())
+ }
+}
+
+fn get_branches(current: &OsStr) -> Vec<CompletionCandidate> {
+ let mut output = vec![];
+
+ let Some(current) = current.to_str() else {
+ return output;
+ };
+
+ let Ok(git_output) = Command::new("git")
+ .args(["branch", "--list", "--format", "'%(refname:short)'"])
+ .current_dir("/etc/nixos")
+ .output()
+ else {
+ return output;
+ };
+
+ if !git_output.status.success() {
+ return output;
+ }
+
+ let Ok(possible) = String::from_utf8(git_output.stdout) else {
+ return output;
+ };
+
+ for possible in possible.trim().split('\n') {
+ if possible.starts_with(current) {
+ output.push(CompletionCandidate::new(possible));
+ }
+ }
+
+ output
+}