fix a bunch of warnings!

This commit is contained in:
Qyriad 2026-03-10 18:46:55 +01:00
parent b49032d5f4
commit b48209a33a
6 changed files with 10 additions and 84 deletions

View file

@ -11,50 +11,6 @@ use clap::ColorChoice;
use crate::prelude::*; use crate::prelude::*;
//#[derive(Debug, Clone, PartialEq)]
//#[derive(clap::Args)]
//#[group(required = true, multiple = false)]
//pub enum Config
//{
// Flake,
//}
#[derive(Debug, Clone, PartialEq)]
pub struct NixOsOption {
name: String,
value: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct NixOptionParseError(pub Box<str>);
impl Display for NixOptionParseError {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{}", self.0)
}
}
impl From<String> for NixOptionParseError {
fn from(value: String) -> Self {
Self(value.into_boxed_str())
}
}
impl StdError for NixOptionParseError {}
impl FromStr for NixOsOption {
type Err = NixOptionParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
// FIXME: allow escaping equals sign?
let Some(delim) = s.find('=') else {
return Err(format!("equals sign not found in {}", s).into());
};
todo!();
}
}
#[derive(Debug, Clone, PartialEq, clap::Parser)] #[derive(Debug, Clone, PartialEq, clap::Parser)]
pub struct AppendCmd { pub struct AppendCmd {
#[arg(required = true)] #[arg(required = true)]
@ -64,15 +20,10 @@ pub struct AppendCmd {
pub value: Arc<str>, pub value: Arc<str>,
} }
#[derive(Debug, Clone, PartialEq, clap::Parser)]
pub struct DeltaCmd {}
#[derive(Debug, Clone, PartialEq, clap::Subcommand)] #[derive(Debug, Clone, PartialEq, clap::Subcommand)]
#[command(flatten_help = true)] #[command(flatten_help = true)]
pub enum Subcommand { pub enum Subcommand {
Append(AppendCmd), Append(AppendCmd),
// TODO: rename
Delta(DeltaCmd),
} }
static DEFAULT_PATH: LazyLock<Box<OsStr>> = LazyLock::new(|| { static DEFAULT_PATH: LazyLock<Box<OsStr>> = LazyLock::new(|| {
@ -114,16 +65,3 @@ pub struct Args {
#[command(subcommand)] #[command(subcommand)]
pub subcommand: Subcommand, pub subcommand: Subcommand,
} }
///// Flakeref to a base configuration to modify.
//#[arg(group = "config", long, default_value("."))]
//#[arg(long, default_value(Some(".")))]
//flake: Option<Option<Box<OsStr>>>,
//
//#[arg(group = "config", long)]
//expr: Option<String>,
//impl Parser {
// fn eval_cmd(&self) {
// todo!();
// }
//}

View file

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: EUPL-1.1 // SPDX-License-Identifier: EUPL-1.1
// The entire point of this module.
#![allow(clippy::declare_interior_mutable_const)]
use std::{ use std::{
env, env,
sync::{LazyLock, OnceLock}, sync::{LazyLock, OnceLock},
@ -22,13 +25,7 @@ fn is_color_reqd() -> bool {
fn is_clicolor_forced() -> bool { fn is_clicolor_forced() -> bool {
env::var("CLICOLOR_FORCE") env::var("CLICOLOR_FORCE")
.map(|value| { .map(|value| !(value.is_empty() || value == "0"))
if value.is_empty() || value == "0" {
false
} else {
true
}
})
.unwrap_or(false) .unwrap_or(false)
} }

View file

@ -41,7 +41,7 @@ pub(crate) mod prelude {
use prelude::*; use prelude::*;
pub mod args; pub mod args;
pub use args::{AppendCmd, Args, DeltaCmd}; pub use args::{AppendCmd, Args};
mod color; mod color;
pub use color::{_CLI_ENABLE_COLOR, SHOULD_COLOR}; pub use color::{_CLI_ENABLE_COLOR, SHOULD_COLOR};
pub mod line; pub mod line;
@ -80,11 +80,6 @@ static MK_OVERRIDE_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(?-u)\bmkOverride\s+\((?<priority>[\d-]+)\)").unwrap() Regex::new(r"(?-u)\bmkOverride\s+\((?<priority>[\d-]+)\)").unwrap()
}); });
#[tracing::instrument(level = "debug")]
pub fn do_delta(args: Arc<Args>, delta_args: DeltaCmd) -> Result<(), BoxDynError> {
todo!();
}
#[tracing::instrument(level = "debug")] #[tracing::instrument(level = "debug")]
pub fn do_append(args: Arc<Args>, append_args: AppendCmd) -> Result<(), BoxDynError> { pub fn do_append(args: Arc<Args>, append_args: AppendCmd) -> Result<(), BoxDynError> {
let filepath = Path::new(&args.file); let filepath = Path::new(&args.file);
@ -109,9 +104,9 @@ pub fn do_append(args: Arc<Args>, append_args: AppendCmd) -> Result<(), BoxDynEr
let new_pri_line = get_next_prio_line( let new_pri_line = get_next_prio_line(
source_file.clone(), source_file.clone(),
append_args.name.into(), append_args.name,
new_pri, new_pri,
append_args.value.into(), append_args.value,
)?; )?;
debug!("new_pri_line={new_pri_line}"); debug!("new_pri_line={new_pri_line}");
@ -154,7 +149,7 @@ fn maybe_extract_prio_from_line(line: &SourceLine) -> Option<i64> {
pub fn get_where(dynamic_nix: SourceFile) -> Result<i64, BoxDynError> { pub fn get_where(dynamic_nix: SourceFile) -> Result<i64, BoxDynError> {
let lines = dynamic_nix.lines()?; let lines = dynamic_nix.lines()?;
let prio = lines let prio = lines
.into_iter() .iter()
.filter_map(maybe_extract_prio_from_line) .filter_map(maybe_extract_prio_from_line)
.sorted_unstable() .sorted_unstable()
.next() // Priorities with lower integer values are "stronger" priorities. .next() // Priorities with lower integer values are "stronger" priorities.

View file

@ -7,7 +7,6 @@ use std::num::NonZeroU64;
#[allow(unused_imports)] #[allow(unused_imports)]
use crate::prelude::*; use crate::prelude::*;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Line(pub u64); pub struct Line(pub u64);
@ -43,5 +42,3 @@ impl Line {
self.0 + 1 self.0 + 1
} }
} }
pub struct Lines(Vec<Line>);

View file

@ -34,7 +34,6 @@ fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
use dynix::args::Subcommand::*; use dynix::args::Subcommand::*;
match &args.subcommand { match &args.subcommand {
Append(append_args) => dynix::do_append(args.clone(), append_args.clone())?, Append(append_args) => dynix::do_append(args.clone(), append_args.clone())?,
Delta(delta_args) => dynix::do_delta(args.clone(), delta_args.clone())?,
}; };
} }

View file

@ -40,7 +40,7 @@ pub fn replace_file<'a>(
drop(writer); drop(writer);
// Rename the temporary file to the new file, which is atomic (TODO: I think). // Rename the temporary file to the new file, which is atomic (TODO: I think).
fs_err::rename(&tmp_path, &path)?; fs_err::rename(&tmp_path, path)?;
Ok(()) Ok(())
} }
@ -62,7 +62,7 @@ impl SourceLine {
} }
pub fn text_bytes(&self) -> Arc<[u8]> { pub fn text_bytes(&self) -> Arc<[u8]> {
let len: usize = self.text.as_bytes().len(); let len: usize = self.text.len();
// We need to consume an Arc, but we are &self. // We need to consume an Arc, but we are &self.
let text = Arc::clone(&self.text); let text = Arc::clone(&self.text);