-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
268 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
pub mod cli { | ||
use std::fmt; | ||
|
||
use clap::{arg, command, Parser}; | ||
use clap::builder::TypedValueParser as _; | ||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Clone)] | ||
pub enum Encoding { | ||
UTF8, | ||
} | ||
|
||
impl Encoding { | ||
pub fn from_str(s: &str) -> Self { | ||
match s { | ||
"utf8" => Encoding::UTF8, | ||
_ => Encoding::UTF8, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Encoding { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{:?}", self) | ||
} | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(name = "charsplit")] | ||
#[command(bin_name = "charsplit")] | ||
#[command(about = "Split a string into its bytes and characters")] | ||
#[command(long_about = "charsplit is a small utility tool that will give you information about your string input. It will split the string into its bytes and graphemes, and give you information about them.")] | ||
#[command(version = "0.1.0")] | ||
pub struct Arguments { | ||
/// What encoding to use | ||
#[arg( | ||
short, | ||
long, | ||
default_value_t = Encoding::UTF8, | ||
value_parser = clap::builder::PossibleValuesParser::new(["UTF8"]) | ||
.map(|value| Encoding::from_str(&value)) | ||
)] | ||
pub encoding: Encoding, | ||
|
||
#[arg(default_value_t = String::new())] | ||
pub text: String, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.