Skip to content

Commit

Permalink
Support format with string argument for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jun 28, 2021
1 parent 0e1ff05 commit 67ebf69
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/cd.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continuous Deployment
name: Release

on:
push:
Expand All @@ -15,15 +15,15 @@ jobs:
rust: [stable]
include:
- os: macos-latest
artifact_prefix: macos
artifact_prefix: darwin-amd64
target: x86_64-apple-darwin
binary_postfix: ""
- os: ubuntu-latest
artifact_prefix: linux
artifact_prefix: linux-amd64
target: x86_64-unknown-linux-gnu
binary_postfix: ""
- os: windows-latest
artifact_prefix: windows
artifact_prefix: windows-amd64
target: x86_64-pc-windows-msvc
binary_postfix: ".exe"

Expand All @@ -48,14 +48,14 @@ jobs:
with:
command: build
toolchain: ${{ matrix.rust }}
args: --release --features="bin" --target ${{ matrix.target }}
args: --release --features bin --target ${{ matrix.target }}

- name: Packaging final binary
shell: bash
run: |
cd target/${{ matrix.target }}/release
BINARY_NAME=autocorrect
RELEASE_NAME=autocorrect
BINARY_NAME=autocorrect${{ matrix.binary_postfix }}
RELEASE_NAME=autocorrect-${{ matrix.artifact_prefix }}
tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
if [[ ${{ runner.os }} == 'Windows' ]]; then
certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
Expand Down
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.4-alpha.0"
version = "0.4.3"

[lib]
name = "autocorrect"
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ release:
cargo release --features="bin"
run:
cargo run --features="bin"
release\:bin:
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/
32 changes: 20 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use autocorrect::{format, format_html};
use clap::{App, Arg, SubCommand};
use clap::{crate_version, App, Arg, SubCommand};
use glob::glob;
use std::fs;
use std::path::Path;

pub fn main() {
let matches = App::new("AutoCorrect")
.author("Jason Lee <huacnlee@gmail.com")
.version("0.4.3")
.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")
Expand All @@ -26,17 +27,24 @@ pub fn main() {
if let Some(matches) = matches.subcommand_matches("format") {
let file_name = matches.value_of("file").unwrap();

for f in glob(file_name).unwrap() {
let path: String;

match f {
Ok(_path) => path = String::from(_path.to_str().unwrap()),
Err(_e) => break,
let path_exist = Path::new(file_name).exists();
if path_exist {
for f in glob(file_name).unwrap() {
let path: String;
match f {
Ok(_path) => path = String::from(_path.to_str().unwrap()),
Err(_e) => break,
}
let raw = fs::read_to_string(path).unwrap();
let raw = raw.as_str();
if matches.is_present("html") {
println!("{}", format(raw));
} else {
println!("{}", format_html(raw));
}
}

let raw = fs::read_to_string(path).unwrap();
let raw = raw.as_str();

} else {
let raw = file_name;
if matches.is_present("html") {
println!("{}", format(raw));
} else {
Expand Down

0 comments on commit 67ebf69

Please sign in to comment.