11use clap:: { App , Arg } ;
2- use std:: str:: FromStr ;
32
4- pub enum ReadingMode {
3+ #[ derive( PartialEq ) ]
4+ pub enum CandlesRetrievalMode {
55 Stdin ,
66 CsvFile ,
7- }
8-
9- impl FromStr for ReadingMode {
10- type Err = & ' static str ;
11-
12- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
13- match s {
14- "Stdin" => Ok ( ReadingMode :: Stdin ) ,
15- "CsvFile" => Ok ( ReadingMode :: CsvFile ) ,
16- _ => Err ( "no match" ) ,
17- }
18- }
7+ Yahoo ,
198}
209
2110pub struct CliOptions {
22- pub reading_mode : ReadingMode ,
11+ pub mode : CandlesRetrievalMode ,
2312 pub file_path : Option < String > ,
2413 pub chart_name : Option < String > ,
2514 pub bear_color : Option < String > ,
2615 pub bull_color : Option < String > ,
16+ pub ticker : Option < String > ,
17+ pub interval : String ,
2718}
2819
2920pub fn get_args ( ) -> CliOptions {
3021 let matches = App :: new ( env ! ( "CARGO_PKG_NAME" ) )
3122 . version ( env ! ( "CARGO_PKG_VERSION" ) )
3223 . author ( env ! ( "CARGO_PKG_AUTHORS" ) )
3324 . arg (
34- Arg :: with_name ( "READING_MODE " )
35- . short ( "r " )
36- . long ( "reading- mode" )
37- . help ( "Make the program reads and parse candles from stdin ." )
38- . possible_values ( & [ "stdin" , "csv-file" , "json-file" ] )
25+ Arg :: with_name ( "MODE " )
26+ . short ( "m " )
27+ . long ( "mode" )
28+ . help ( "Select the method for retrieving the candles." )
29+ . possible_values ( & [ "stdin" , "csv-file" , "json-file" , "yahoo-fetch" ] )
3930 . takes_value ( true )
4031 . required ( true ) ,
4132 )
4233 . arg (
4334 Arg :: with_name ( "FILE" )
4435 . short ( "f" )
4536 . long ( "file" )
46- . help ( "File to read candles from, if reading-mode is `*-file .`" )
37+ . help ( "[MODE:*-file] File to read candles from.`" )
4738 . takes_value ( true ) ,
4839 )
4940 . arg (
@@ -64,14 +55,35 @@ pub fn get_args() -> CliOptions {
6455 . help ( "Sets the ascending candles color in hexadecimal." )
6556 . takes_value ( true ) ,
6657 )
58+ . arg (
59+ Arg :: with_name ( "TICKER" )
60+ . long ( "ticker" )
61+ . takes_value ( true )
62+ . required_if ( "MODE" , "yahoo-fetch" )
63+ . help ( "[MODE:*-fetch] The broker-side ticker of the asset you want to plot." ) ,
64+ )
65+ . arg (
66+ Arg :: with_name ( "INTERVAL" )
67+ . long ( "interval" )
68+ . default_value ( "1d" )
69+ . possible_values ( & [
70+ "1m" , "2m" , "5m" , "15m" , "30m" , "60m" , "90m" , "1h" , "1d" , "5d" , "1wk" , "1mo" ,
71+ "3mo" ,
72+ ] )
73+ . takes_value ( true )
74+ . help ( "[MODE:*-fetch] The interval you want to retrieve the candles from the API" ) ,
75+ )
6776 . get_matches ( ) ;
6877
6978 return CliOptions {
70- reading_mode : match matches. value_of ( "READING_MODE" ) . unwrap ( ) {
71- "stdin" => ReadingMode :: Stdin ,
72- "csv-file" => ReadingMode :: CsvFile ,
79+ mode : match matches. value_of ( "MODE" ) . unwrap ( ) {
80+ "stdin" => CandlesRetrievalMode :: Stdin ,
81+ "csv-file" => CandlesRetrievalMode :: CsvFile ,
82+ "yahoo-fetch" => CandlesRetrievalMode :: Yahoo ,
7383 _ => panic ! ( "Invalid reading mode." ) ,
7484 } ,
85+ interval : matches. value_of ( "INTERVAL" ) . unwrap ( ) . to_string ( ) ,
86+ ticker : matches. value_of ( "TICKER" ) . map ( |s| s. to_string ( ) ) ,
7587 file_path : matches. value_of ( "FILE" ) . map ( |s| s. to_string ( ) ) ,
7688 chart_name : matches. value_of ( "CHART_NAME" ) . map ( |s| s. to_string ( ) ) ,
7789 bear_color : matches. value_of ( "BEAR_COLOR" ) . map ( |s| s. to_string ( ) ) ,
0 commit comments