Skip to content

Commit

Permalink
Improve cmd argument
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jun 28, 2021
1 parent e99de52 commit 850fa74
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
name = "autocorrect"
readme = "README.md"
repository = "https://github.com/huacnlee/auto-correct.rs"
version = "0.4.3"
version = "0.4.4"

[lib]
name = "autocorrect"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ run:
cargo run --features="bin"
release\:arm:
cargo +stable build --release --features bin --target aarch64-apple-darwin
cd target/aarch64-apple-darwin/release; tar czvf autocorrect-aarch64-apple-darwin.tar.gz autocorrect; mv autocorrect-aarch64-apple-darwin.tar.gz ~/Downloads/
cd target/aarch64-apple-darwin/release; tar czvf autocorrect-darwin-arm64.tar.gz autocorrect; mv autocorrect-darwin-arm64.tar.gz ~/Downloads/
ls -lh ~/Downloads/autocorrect*.tar.gz
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,60 @@ Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-wi

## Install

```bash
$ curl -sSL https://git.io/JckA6 | bash
```

after that, you will get `/usr/local/bin/autocorrect` command.

```bash
$ autocorrect -h
AutoCorrect 0.4.4
Jason Lee <[email protected]
Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters,
numerical digits and symbols).

USAGE:
autocorrect [FLAGS] [text]

FLAGS:
-h, --help Prints help information
--html Use for HTML format
-V, --version Prints version information

ARGS:
<text> Target filepath or string (Plain text) for format
```

## Usage

```bash
$ autocorrect 你好Hello世界
你好 Hello 世界
$ autocorrect text.md
你好 Hello 世界

$ autocorrect text.md > text-new.md
```

Format HTML

```bash
$ autocorrect --html '<p>你好hello世界</p><p>你好world世界</p>'
<p>你好 hello 世界</p><p>你好 world 世界</p>

$ autocorrect --html text.html
```

## Usage in Rust

In your Cargo.toml

```toml
[dependencies]
autocorrect = "0.4.0"
```

## Usage

Use `autocorrect::format` to format plain text.

```rust
Expand Down
23 changes: 7 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use autocorrect::{format, format_html};
use clap::{crate_version, App, Arg, SubCommand};
use clap::{crate_version, App, Arg};
use glob::glob;
use std::fs;
use std::path::Path;
Expand All @@ -9,24 +9,15 @@ pub fn main() {
.author("Jason Lee <[email protected]")
.version(crate_version!())
.about("Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).")
.subcommand(
SubCommand::with_name("format")
.about("Format content")
.arg(
Arg::with_name("file").help("Target file (Plain text) for format").takes_value(true).required(true)
)
.arg(
Arg::with_name("html").long("html").help("Use for HTML format")
)
.arg(
Arg::with_name("auto-correct").short("a").long("auto-correct").help("Auto-correct offenses.")
)
.arg(
Arg::with_name("text").help("Target filepath or string (Plain text) for format").takes_value(true).required(false)
)
.arg(
Arg::with_name("html").long("html").help("Use for HTML format")
)
.get_matches();

if let Some(matches) = matches.subcommand_matches("format") {
let file_name = matches.value_of("file").unwrap();

if let Some(file_name) = matches.value_of("text") {
let path_exist = Path::new(file_name).exists();
if path_exist {
for f in glob(file_name).unwrap() {
Expand Down

0 comments on commit 850fa74

Please sign in to comment.