@@ -2,55 +2,43 @@ use ::num2words::{Currency, Lang, Num2Words, Output};
22use std:: env;
33use std:: str:: FromStr ;
44
5- const HELP : & str = r#"Usage: num2words <number> [--lang|-l lang] [--to|-t to]
6-
7- For more information about all of the available languages and to
8- tags, please type the following:
9- $ num2words --help lang
10- $ num2words --help to"# ;
11-
12- const HELP_LANG : & str = r#"Available languages:
13- * en: English
14-
15- This list can be expanded! Do not hesitate to contribute!
16- https://github.com/Ballasi/num2words"# ;
17-
18- const HELP_TO : & str = r#"Available to tags:
19- * cardinal
20- * ordinal
21- * ordinal_num
22- * year
23- * any currency
24-
25- Currencies available:
26- * AUD
27- * CAD
28- * DOLLAR (generic, non-localized dollar)
29- * EUR
30- * GBP
31- * USD"# ;
5+ const HELP : & str = r#"NAME:
6+ num2words - convert numbers into words
7+
8+ USAGE:
9+ num2words <number> [options]
10+ num2words --help
11+
12+ VERSION:
13+ v{{VERSION}}
14+
15+ COMMANDS:
16+ GLOBAL OPTIONS:
17+ --lang value, -l value set language (default: "en")
18+ --to output, -t output set output (default: "cardinal")
19+ --help, -h show help
20+ --version, -v print the version
21+
22+ AVAILABLE LANGUAGES:
23+ en: English
24+
25+ AVAILABLE OUTPUTS:
26+ cardinal: forty-two (42)
27+ ordinal: forty-second (42)
28+ ordinal_num: 42nd (42)
29+ year: nineteen oh-one (1901)
30+ currency: forty-two dollars and one cent (42.01)
31+
32+ AVAILABLE CURRENCIES:
33+ AUD australian dollar
34+ CAD canadian dollar
35+ DOLLAR dollar
36+ EUR euro
37+ GBP pound
38+ USD US dollar"# ;
3239
3340fn help ( ) {
34- println ! ( "{}" , HELP )
35- }
36-
37- fn help_lang ( ) {
38- println ! ( "{}" , HELP_LANG )
39- }
40-
41- fn help_to ( ) {
42- println ! ( "{}" , HELP_TO )
43- }
44-
45- fn handle_help ( mut args : std:: env:: Args ) {
46- match args. next ( ) {
47- Some ( cmd) => match cmd. as_str ( ) {
48- "lang" => help_lang ( ) ,
49- "to" => help_to ( ) ,
50- _ => help ( ) ,
51- } ,
52- None => help ( ) ,
53- }
41+ println ! ( "{}" , HELP . replace( "{{VERSION}}" , env!( "CARGO_PKG_VERSION" ) ) )
5442}
5543
5644fn parse_number_and_print ( num : String , lang : Lang , output : Output , currency : Currency ) {
@@ -145,7 +133,8 @@ fn main() {
145133
146134 match args. next ( ) {
147135 Some ( num) => match num. as_str ( ) {
148- "--help" | "-h" => handle_help ( args) ,
136+ "--help" | "-h" => help ( ) ,
137+ "--version" | "-v" => println ! ( "{} v{}" , env!( "CARGO_PKG_NAME" ) , env!( "CARGO_PKG_VERSION" ) ) ,
149138 _ => handle_cmd ( num, args) ,
150139 } ,
151140 None => help ( ) ,
0 commit comments