Initial Commit

This commit is contained in:
Uttarayan Mondal
2021-03-09 17:50:49 +05:30
commit 0ab957e037
4 changed files with 236 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
Generated
+121
View File
@@ -0,0 +1,121 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "hermit-abi"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
[[package]]
name = "ntext"
version = "0.2.1"
source = "git+https://github.com/uttarayan21/ntext-rs#653648e3ce86aeb8085463b26f6b2d8a390938f0"
[[package]]
name = "ntext-cli"
version = "0.1.0"
dependencies = [
"clap",
"ntext",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "ntext-cli"
version = "0.1.0"
authors = ["Uttarayan Mondal <uttarayan21@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ntext = { git = "https://github.com/uttarayan21/ntext-rs" }
clap = "2.33.3"
+101
View File
@@ -0,0 +1,101 @@
extern crate clap;
extern crate ntext;
use clap::{App, Arg};
use ntext::{to_text, Formatting};
fn main() {
let matches = App::new("ntext-cli")
.version("1.0")
.author("Uttarayan Mondal")
.about("Converts numbers to words")
.arg(
Arg::with_name("number")
.help("The number to convert to words")
.required(true), // .index(1),
)
.arg(
Arg::with_name("capitalize")
.short("c")
.long("capitalize")
.possible_values(&["true", "false"])
.value_name("capitalize")
.help("Capitalize all the words")
.takes_value(true),
)
.arg(
Arg::with_name("seperator")
.short("s")
.long("seperator")
.value_name("seperator")
.help("Seperator seperating all the words")
.takes_value(true),
)
.arg(
Arg::with_name("tens_seperator")
.short("t")
.long("tens")
.value_name("tens_seperator")
.help("Seperator seperating tens place words")
.takes_value(true),
)
.arg(
Arg::with_name("digits_seperator")
.short("d")
.long("digits")
.help("Seperator seperating all the digits")
.takes_value(true),
)
.arg(
Arg::with_name("place_seperator")
.short("p")
.long("place")
.help("Seperator seperating numbers from its place value")
.takes_value(true),
)
.arg(
Arg::with_name("noformat")
.short("n")
.long("noformat")
.help("No formatting at all (can be overriden by flags)"),
)
.get_matches();
let number = matches.value_of("number").unwrap().parse::<usize>();
let capitalize = matches
.value_of("capitalize")
.unwrap_or("true")
.parse::<bool>()
.unwrap();
let noformat = matches.is_present("noformat");
let seperator = matches.value_of("seperator");
let tens_seperator = matches.value_of("tens_seperator");
let digit_seperator = matches.value_of("digits_seperator");
let place_seperator = matches.value_of("place_seperator");
let mut fmt = Formatting::default();
if noformat {
fmt = Formatting::none();
}
fmt = Formatting {
capitalize,
digit_seperator: match (digit_seperator, seperator) {
(None, None) => fmt.digit_seperator,
(Some(dsep), _) => Some(dsep),
(None, Some(sep)) => Some(sep),
},
tens_seperator: match (tens_seperator, seperator) {
(None, None) => fmt.tens_seperator,
(Some(tsep), _) => Some(tsep),
(None, Some(sep)) => Some(sep),
},
place_seperator: match (place_seperator, seperator) {
(None, None) => fmt.place_seperator,
(Some(psep), _) => Some(psep),
(None, Some(sep)) => Some(sep),
},
};
match number {
Ok(num) => println!("{}", to_text!(num, &fmt)),
Err(e) => eprintln!("Error: {} \n<number> field should be a number", e),
}
}