Skip to content

Commit

Permalink
Upgrade to clap 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
misalcedo committed Jan 4, 2024
1 parent 5ab9183 commit 24147a0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <miguel@salcedo.cc>"]
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -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 }
walkdir = { version = "2.4", optional = true }
19 changes: 7 additions & 12 deletions bin/arguments.rs
Original file line number Diff line number Diff line change
@@ -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<Commands>,
Expand All @@ -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,
}
Expand Down
49 changes: 40 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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<io::Error> for LiterateError {
fn from(e: io::Error) -> Self {
Self::IO(e)
}
}

impl From<walkdir::Error> for LiterateError {
fn from(e: walkdir::Error) -> Self {
Self::Walk(e)
}
}

impl From<StripPrefixError> 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 {
}

0 comments on commit 24147a0

Please sign in to comment.