Compare commits

..

2 commits

Author SHA1 Message Date
fe6cd2c83f feat: parse literal text from CLI 2022-11-28 12:24:01 +01:00
3bfaff7031 chore: fix crate packaging, add changelog 2022-11-28 11:57:00 +01:00
5 changed files with 132 additions and 12 deletions

9
CHANGELOG.md Normal file
View file

@ -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
<!-- generated by git-cliff -->

View file

@ -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"

View file

@ -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:

70
cliff.toml Normal file
View file

@ -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 = """
<!-- generated by git-cliff -->
"""
[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

View file

@ -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 <FILE> 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));
}
}
};
}