diff --git a/Cargo.toml b/Cargo.toml index a341ad5d..42368110 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "literate" description = "A literate programming tool that extracts code written in your Markdown files." -version = "0.5.1" +version = "0.6.0" authors = ["Miguel D. Salcedo "] edition = "2021" license = "Apache-2.0" @@ -29,10 +29,9 @@ walk =["walkdir"] [dependencies] anyhow = { version = "1.0", optional = true } -clap = { version = "3.0", features = ["derive"], optional = true } +clap = { version = "4.4", features = ["derive"], optional = true } pulldown-cmark = "0.9" -regex = "1.5" -thiserror = "1.0" +regex = "1.10" tracing = "0.1" tracing-subscriber = { version = "0.3", optional = true } -walkdir = { version = "2.3.2", optional = true } \ No newline at end of file +walkdir = { version = "2.4", optional = true } \ No newline at end of file diff --git a/bin/arguments.rs b/bin/arguments.rs index fc6319fe..88a91ee3 100644 --- a/bin/arguments.rs +++ b/bin/arguments.rs @@ -1,13 +1,9 @@ -use clap::{AppSettings, Args, Parser, Subcommand}; +use clap::{Args, Parser, Subcommand}; use std::path::PathBuf; #[derive(Clone, Debug, Eq, Parser, PartialEq)] #[clap(author, version, about)] -#[clap(global_setting(AppSettings::PropagateVersion))] -#[clap(global_setting(AppSettings::InferLongArgs))] -#[clap(global_setting(AppSettings::InferSubcommands))] -#[clap(global_setting(AppSettings::ArgsNegateSubcommands))] -#[clap(global_setting(AppSettings::UseLongFormatForHelpSubcommand))] +#[clap(args_conflicts_with_subcommands = true, infer_subcommands = true)] pub struct Arguments { #[clap(subcommand)] pub command: Option, @@ -30,17 +26,16 @@ pub struct Verbosity { #[clap( short, long, - global(true), + action = clap::ArgAction::Count, help_heading("VERBOSITY"), - conflicts_with_all(&["debug", "trace"]), - parse(from_occurrences) + conflicts_with_all(&["debug", "trace"]) )] /// Make the program more talkative. - pub verbose: usize, - #[clap(short, long, global(true), help_heading("VERBOSITY"), conflicts_with_all(&["verbose", "trace"]))] + pub verbose: u8, + #[clap(short, long, help_heading("VERBOSITY"), conflicts_with_all(&["verbose", "trace"]))] /// Print debug messages. pub debug: bool, - #[clap(short, long, global(true), help_heading("VERBOSITY"), conflicts_with_all(&["verbose", "debug"]))] + #[clap(short, long, help_heading("VERBOSITY"), conflicts_with_all(&["verbose", "debug"]))] /// Print trace messages. pub trace: bool, } diff --git a/src/error.rs b/src/error.rs index b229e32f..ad2ae03f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,15 +1,46 @@ -use thiserror::Error; +use std::error::Error; +use std::fmt::{Display, Formatter}; +use std::io; +use std::path::StripPrefixError; -#[derive(Error, Debug)] +#[derive(Debug)] pub enum LiterateError { - #[error(transparent)] - IO(#[from] std::io::Error), + IO(io::Error), #[cfg(feature = "walk")] - #[error(transparent)] - Walk(#[from] walkdir::Error), + Walk(walkdir::Error), #[cfg(feature = "walk")] - #[error(transparent)] - Prefix(#[from] std::path::StripPrefixError), - #[error("Unknown error")] + Prefix(StripPrefixError), Unknown, } + +impl From for LiterateError { + fn from(e: io::Error) -> Self { + Self::IO(e) + } +} + +impl From for LiterateError { + fn from(e: walkdir::Error) -> Self { + Self::Walk(e) + } +} + +impl From for LiterateError { + fn from(e: StripPrefixError) -> Self { + Self::Prefix(e) + } +} + +impl Display for LiterateError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + LiterateError::IO(e) => e.fmt(f), + LiterateError::Walk(e) => e.fmt(f), + LiterateError::Prefix(e) => e.fmt(f), + LiterateError::Unknown => write!(f ,"Unknown error") + } + } +} + +impl Error for LiterateError { +} \ No newline at end of file