fix a bunch of warnings!
This commit is contained in:
parent
b49032d5f4
commit
b48209a33a
6 changed files with 10 additions and 84 deletions
62
src/args.rs
62
src/args.rs
|
|
@ -11,50 +11,6 @@ use clap::ColorChoice;
|
|||
|
||||
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)]
|
||||
pub struct AppendCmd {
|
||||
#[arg(required = true)]
|
||||
|
|
@ -64,15 +20,10 @@ pub struct AppendCmd {
|
|||
pub value: Arc<str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, clap::Parser)]
|
||||
pub struct DeltaCmd {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, clap::Subcommand)]
|
||||
#[command(flatten_help = true)]
|
||||
pub enum Subcommand {
|
||||
Append(AppendCmd),
|
||||
// TODO: rename
|
||||
Delta(DeltaCmd),
|
||||
}
|
||||
|
||||
static DEFAULT_PATH: LazyLock<Box<OsStr>> = LazyLock::new(|| {
|
||||
|
|
@ -114,16 +65,3 @@ pub struct Args {
|
|||
#[command(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!();
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
11
src/color.rs
11
src/color.rs
|
|
@ -2,6 +2,9 @@
|
|||
//
|
||||
// SPDX-License-Identifier: EUPL-1.1
|
||||
|
||||
// The entire point of this module.
|
||||
#![allow(clippy::declare_interior_mutable_const)]
|
||||
|
||||
use std::{
|
||||
env,
|
||||
sync::{LazyLock, OnceLock},
|
||||
|
|
@ -22,13 +25,7 @@ fn is_color_reqd() -> bool {
|
|||
|
||||
fn is_clicolor_forced() -> bool {
|
||||
env::var("CLICOLOR_FORCE")
|
||||
.map(|value| {
|
||||
if value.is_empty() || value == "0" {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.map(|value| !(value.is_empty() || value == "0"))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
|
|
|
|||
13
src/lib.rs
13
src/lib.rs
|
|
@ -41,7 +41,7 @@ pub(crate) mod prelude {
|
|||
use prelude::*;
|
||||
|
||||
pub mod args;
|
||||
pub use args::{AppendCmd, Args, DeltaCmd};
|
||||
pub use args::{AppendCmd, Args};
|
||||
mod color;
|
||||
pub use color::{_CLI_ENABLE_COLOR, SHOULD_COLOR};
|
||||
pub mod line;
|
||||
|
|
@ -80,11 +80,6 @@ static MK_OVERRIDE_RE: LazyLock<Regex> = LazyLock::new(|| {
|
|||
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")]
|
||||
pub fn do_append(args: Arc<Args>, append_args: AppendCmd) -> Result<(), BoxDynError> {
|
||||
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(
|
||||
source_file.clone(),
|
||||
append_args.name.into(),
|
||||
append_args.name,
|
||||
new_pri,
|
||||
append_args.value.into(),
|
||||
append_args.value,
|
||||
)?;
|
||||
|
||||
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> {
|
||||
let lines = dynamic_nix.lines()?;
|
||||
let prio = lines
|
||||
.into_iter()
|
||||
.iter()
|
||||
.filter_map(maybe_extract_prio_from_line)
|
||||
.sorted_unstable()
|
||||
.next() // Priorities with lower integer values are "stronger" priorities.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use std::num::NonZeroU64;
|
|||
#[allow(unused_imports)]
|
||||
use crate::prelude::*;
|
||||
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Line(pub u64);
|
||||
|
||||
|
|
@ -43,5 +42,3 @@ impl Line {
|
|||
self.0 + 1
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Lines(Vec<Line>);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
|
|||
use dynix::args::Subcommand::*;
|
||||
match &args.subcommand {
|
||||
Append(append_args) => dynix::do_append(args.clone(), append_args.clone())?,
|
||||
Delta(delta_args) => dynix::do_delta(args.clone(), delta_args.clone())?,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ pub fn replace_file<'a>(
|
|||
drop(writer);
|
||||
|
||||
// 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(())
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ impl SourceLine {
|
|||
}
|
||||
|
||||
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.
|
||||
let text = Arc::clone(&self.text);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue