Skip to content

Commit

Permalink
Merge pull request #3 from panther-king/develop
Browse files Browse the repository at this point in the history
Up to 0.4.0
  • Loading branch information
panther-king authored Mar 16, 2024
2 parents 41fe83f + 6d9a0a3 commit 3da389d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "kelp"
version = "0.4.0"
edition = "2018"
edition = "2021"
authors = ["Taro Yamashita <[email protected]>"]
repository = "https://github.com/panther-king/kelp"
keywords = ["conversion", "cli"]
Expand All @@ -11,7 +11,7 @@ description = "A convert tool for Japanese."
documentation = "https://panther-king.github.io/kelp/kelp/"

[dependencies]
clap = "3"
clap = { version = "^4", features = ["derive"] }

[[bin]]
name = "kelp-cli"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Usage

Add `kelp` as a dependency in your `Cargo.toml`

```shell
cargo add kelp
```

```toml
[dependencies]
kelp = "0.4"
Expand Down
95 changes: 40 additions & 55 deletions src/bin/kelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,72 +51,57 @@
extern crate clap;
extern crate kelp;

use clap::{App, Arg};
use clap::Parser;
use kelp::h2z;
use kelp::hira2hkata;
use kelp::hira2kata;
use kelp::kata2hira;
use kelp::z2h;
use kelp::ConvOption;

fn main() {
let matches = App::new("kelp")
.version("0.4")
.author("Taro Yamashita <[email protected]>")
.about("A conversion tool of Japanese")
.arg(
Arg::with_name("INPUT")
.required(true)
.help("A text that you want to convert"),
)
.arg(
Arg::with_name("convert")
.short('c')
.long("conv")
.takes_value(true)
.help("Specified conversion pattern"),
)
.arg(
Arg::with_name("ascii")
.short('a')
.long("ascii")
.help("Convert with ascii if specified"),
)
.arg(
Arg::with_name("digit")
.short('d')
.long("digit")
.help("Convert with digit if specified"),
)
.arg(
Arg::with_name("kana")
.short('k')
.long("kana")
.help("Convert with kana if specified"),
)
.arg(
Arg::with_name("ignore")
.short('i')
.long("ignore")
.takes_value(true)
.help("Specified ignore characters"),
)
.get_matches();
/// A conversion tool of Japanese
#[derive(Debug, Parser)]
#[command(version, about)]
struct Args {
/// Specified conversion pattern
#[arg(short, long)]
conv: String,

/// Convert with ascii if specified
#[arg(short, long)]
ascii: bool,

/// Convert with digit if specified
#[arg(short, long)]
digit: bool,

/// Convert with kana if specified
#[arg(short, long)]
kana: bool,

/// Specified ignore charcters
#[arg(short, long)]
ignore: Option<String>,

text: Option<String>,
}

fn main() {
let args = Args::parse();
let option = ConvOption {
ascii: matches.is_present("ascii"),
digit: matches.is_present("digit"),
ignore: matches.value_of("ignore").unwrap_or("").to_string(),
kana: matches.is_present("digit"),
ascii: args.ascii,
digit: args.digit,
ignore: args.ignore.unwrap_or("".to_string()),
kana: args.kana,
};
let text = matches.value_of("INPUT").unwrap();
let text = args.text.as_deref().unwrap_or("");

let converted = match matches.value_of("convert") {
Some(s) if s == "h2z" => h2z(text, option),
Some(s) if s == "h2hk" => hira2hkata(text, option),
Some(s) if s == "h2k" => hira2kata(text, option),
Some(s) if s == "k2h" => kata2hira(text, option),
Some(s) if s == "z2h" => z2h(text, option),
let converted = match args.conv.as_str() {
"h2z" => h2z(text, option),
"h2hk" => hira2hkata(text, option),
"h2k" => hira2kata(text, option),
"k2h" => kata2hira(text, option),
"z2h" => z2h(text, option),
_ => text.to_string(),
};

Expand Down

0 comments on commit 3da389d

Please sign in to comment.