1
- pub mod boxplot;
2
- pub mod measurements;
3
- pub mod progress;
4
- pub mod speedtest;
5
-
1
+ use cfspeedtest:: speedtest;
2
+ use cfspeedtest:: OutputFormat ;
3
+ use cfspeedtest:: SpeedTestCLIOptions ;
6
4
use clap:: Parser ;
7
- use speedtest:: speed_test;
8
- use speedtest:: PayloadSize ;
9
-
10
- #[ derive( Clone , Copy , Debug ) ]
11
- enum OutputFormat {
12
- Csv ,
13
- Json ,
14
- JsonPretty ,
15
- }
16
-
17
- impl OutputFormat {
18
- pub fn from ( output_format_string : String ) -> Result < Self , String > {
19
- match output_format_string. to_lowercase ( ) . as_str ( ) {
20
- "csv" => Ok ( Self :: Csv ) ,
21
- "json" => Ok ( Self :: Json ) ,
22
- "json_pretty" | "json-pretty" => Ok ( Self :: JsonPretty ) ,
23
- _ => Err ( "Value needs to be one of csv, json or json-pretty" . to_string ( ) ) ,
24
- }
25
- }
26
- }
27
-
28
- /// Unofficial CLI for speed.cloudflare.com
29
- #[ derive( Parser , Debug ) ]
30
- #[ command( author, version, about, long_about = None ) ]
31
- pub ( crate ) struct SpeedTestOptions {
32
- /// Number of test runs per payload size. Needs to be at least 4
33
- #[ arg( value_parser = clap:: value_parser!( u32 ) . range( 4 ..1000 ) , short, long, default_value_t = 10 ) ]
34
- nr_tests : u32 ,
35
-
36
- /// Number of latency tests to run
37
- #[ arg( long, default_value_t = 25 ) ]
38
- nr_latency_tests : u32 ,
39
-
40
- /// The max payload size in bytes to use [100k, 1m, 10m, 25m or 100m]
41
- #[ arg( value_parser = parse_payload_size, short, long, default_value_t = PayloadSize :: M10 ) ]
42
- max_payload_size : PayloadSize ,
43
-
44
- /// Set the output format [csv, json or json-pretty] >
45
- /// This silences all other output to stdout
46
- #[ arg( value_parser = parse_output_format, short, long) ]
47
- output_format : Option < OutputFormat > ,
48
-
49
- /// Enable verbose output i.e. print out boxplots of the measurements
50
- #[ arg( short, long) ]
51
- verbose : bool ,
5
+ use std:: net:: IpAddr ;
52
6
53
- /// Force usage of IPv4
54
- #[ arg( long) ]
55
- ipv4 : bool ,
7
+ use speedtest:: speed_test;
56
8
57
- /// Force usage of IPv6
58
- #[ arg( long) ]
59
- ipv6 : bool ,
60
- }
61
- use std:: net:: IpAddr ;
62
9
fn main ( ) {
63
10
env_logger:: init ( ) ;
64
- let options = SpeedTestOptions :: parse ( ) ;
65
- if options. output_format . is_none ( ) {
11
+ let options = SpeedTestCLIOptions :: parse ( ) ;
12
+ if options. output_format == OutputFormat :: StdOut {
66
13
println ! ( "Starting Cloudflare speed test" ) ;
67
14
}
68
15
let client;
@@ -82,11 +29,3 @@ fn main() {
82
29
options,
83
30
) ;
84
31
}
85
-
86
- fn parse_payload_size ( input_string : & str ) -> Result < PayloadSize , String > {
87
- PayloadSize :: from ( input_string. to_string ( ) )
88
- }
89
-
90
- fn parse_output_format ( input_string : & str ) -> Result < OutputFormat , String > {
91
- OutputFormat :: from ( input_string. to_string ( ) )
92
- }
0 commit comments