diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0649e13 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [0.1.0] - 2022-11-28 + +Initial release + + diff --git a/Cargo.toml b/Cargo.toml index 567915d..e1c7ee2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ authors = ["ThetaDev"] license = "GPL-3.0" description = "Romanize hiragana, katakana and kanji (Japanese text)" -include = ["/src", "README.md", "LICENSE"] +include = ["src/*", "tests/*", "benches/*", "README.md", "LICENSE"] [workspace] members = [".", "codegen"] @@ -19,7 +19,7 @@ unicode-normalization = "0.1.22" [dev-dependencies] criterion = "0.4.0" -rstest = { version = "0.15.0", default-features = false } +rstest = { version = "0.16.0", default-features = false } [[bench]] name = "kakasi_benchmark" diff --git a/README.md b/README.md index eab96d7..ace1c92 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,26 @@ assert_eq!(kakasi::is_japanese("日本"), IsJapanese::Maybe); assert_eq!(kakasi::is_japanese("ラスト"), IsJapanese::True); ``` +## CLI + +```sh +$ cargo install kakasi + +## Convert to romaji +$ kakasi Hello 日本! +Hello nihon ! + +## Convert to hiragana +$ kakasi -k Hello 日本! +Hello にほん! + +## Read from file +$ kakasi -f rust_article.txt + +## Read from STDIN +$ echo "Hello 日本" | kakasi +``` + ## Performance Time to convert a 100KB test file using the CLI: diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..a297248 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,70 @@ +# configuration file for git-cliff (0.1.0) + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://tera.netlify.app/docs/#introduction +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = true +# regex for preprocessing the commit messages +commit_preprocessors = [ + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/orhun/git-cliff/issues/${2}))"}, +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "Features"}, + { message = "^fix", group = "Bug Fixes"}, + { message = "^doc", group = "Documentation"}, + { message = "^perf", group = "Performance"}, + { message = "^refactor", group = "Refactor"}, + { message = "^style", group = "Styling"}, + { message = "^test", group = "Testing"}, + { message = "^chore\\(release\\): prepare for", skip = true}, + { message = "^chore", group = "Miscellaneous Tasks"}, + { body = ".*security", group = "Security"}, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = false +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "" +# regex for ignoring tags +ignore_tags = "" +# sort the tags chronologically +date_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# limit the number of commits included in the changelog. +# limit_commits = 42 diff --git a/src/main.rs b/src/main.rs index cfc500a..e333aad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,20 +17,23 @@ fn main() { // Parse commandline arguments let mut hira = false; let mut path = None; + let mut txt = String::new(); let mut args = std::env::args(); + let mut after_opts = false; let pname = args.next().unwrap_or_else(|| "kakasi".to_owned()); - for a in args { - if a.starts_with('-') { + while let Some(a) = args.next() { + if !after_opts && a.starts_with('-') { if a == "-h" || a == "--help" { println!( r#"Transliterate hiragana, katakana and kanji (Japanese text) into romaji (Latin alphabet). -Usage: {} [OPTION] [FILE] +Usage: {} [OPTION] [Japanese text] -With no FILE, read standard input. +With no file or text given, kakasi reads from STDIN. Options: + -f Read from text file -k Transliterate to hiragana instead of romaji -h show this help page"#, pname @@ -38,11 +41,23 @@ Options: return; } else if a == "-k" { hira = true; + } else if a == "-f" { + match args.next() { + Some(p) => path = Some(PathBuf::from(p)), + None => { + eprintln!("no file path given"); + std::process::exit(2); + } + } } else { continue; } - } else if path.is_none() { - path = Some(PathBuf::from(a)); + } else { + after_opts = true; + if !txt.is_empty() { + txt.push(' '); + } + txt += &a; } } @@ -60,9 +75,15 @@ Options: .flatten() .for_each(|l| convert_line(&l, hira)); } - None => std::io::stdin() - .lines() - .flatten() - .for_each(|l| convert_line(&l, hira)), + None => { + if txt.is_empty() { + std::io::stdin() + .lines() + .flatten() + .for_each(|l| convert_line(&l, hira)) + } else { + txt.lines().for_each(|l| convert_line(l, hira)); + } + } }; }