open-i18n / rust-unic

UNIC: Unicode and Internationalization Crates for Rust
https://crates.io/crates/unic
Other
234 stars 24 forks source link

[apps/cli] Support reading from stdin #249 #250

Open LuoZijun opened 5 years ago

LuoZijun commented 5 years ago

Resolve #249


This change is Reviewable

LuoZijun commented 5 years ago

@behnam

If we support accepting parameters from the basic input, the main thread will still blocked when this $ ./unic-echo appears.

Of course, if everyone thinks this is not going to bother the user, the block style approach will be very straightforward. and i am happy to change to a synchronous way.

Use case:

behnam commented 5 years ago

Oh, I think I see what you mean.

I think blocking reading from stdin should only happen if we explicitly want to read from stdin.

One common condition for reading from stdin is when there are no (non-optional) arguments passed to the CLI. (Like unix's echo without any file-names passed to it.)

Another common option is when the argument is one HYPHEN-MINUS ("-"). In this case, the position of the HYPHEN-MINUS can tell us if the stdin text should be placed before or after any other regular argument.

If none of them applies (there's at least one argument passed to the CLI and none of the is "-") the stdin is not even (blocking) opened.

So, all of these cases would result in "Hello world" string to be echoed/inspected:

What do you think?

LuoZijun commented 5 years ago

@behnam

I think that's great.

BTW: Actually is --, not - :)

LuoZijun commented 5 years ago

@behnam ping ?