|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | | -use clap::Parser; |
| 4 | +use clap::{ArgAction, Parser}; |
5 | 5 |
|
6 | 6 | #[cfg(not(target_arch = "wasm32"))] |
7 | 7 | #[tokio::main] |
@@ -46,33 +46,48 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { |
46 | 46 | #[derive(Debug, Parser)] |
47 | 47 | #[command(about = "Starts the Test-Proxy service", version)] |
48 | 48 | struct Args { |
| 49 | + /// Bind to any available port. |
| 50 | + /// |
| 51 | + /// If not set, only port `5000` will be tried. |
| 52 | + /// You can start the `test-proxy` service this way |
| 53 | + /// and pass `PROXY_MANUAL_START=true` when running `cargo test` to easily view trace information. |
| 54 | + #[arg(long)] |
| 55 | + auto: bool, |
| 56 | + |
49 | 57 | /// Allow insecure upstream SSL certs. |
50 | 58 | #[arg(long)] |
51 | 59 | insecure: bool, |
52 | 60 |
|
53 | 61 | /// Number of seconds to automatically shut down when no activity. |
54 | 62 | #[arg(long, default_value_t = 300)] |
55 | | - pub auto_shutdown_in_seconds: u32, |
| 63 | + auto_shutdown_in_seconds: u32, |
56 | 64 |
|
57 | 65 | /// Enable verbose logging. |
58 | | - #[arg(short, long)] |
59 | | - verbose: bool, |
| 66 | + /// |
| 67 | + /// Trace level `INFO` is used by default. |
| 68 | + /// Pass `-v` to enable `DEBUG` level tracing, |
| 69 | + /// or `-vv` to enable `TRACE` level tracing. |
| 70 | + #[arg(short, long, action = ArgAction::Count)] |
| 71 | + verbose: u8, |
60 | 72 | } |
61 | 73 |
|
62 | 74 | impl Args { |
63 | 75 | #[cfg(not(target_arch = "wasm32"))] |
64 | 76 | fn trace_level(&self) -> tracing::level_filters::LevelFilter { |
65 | | - if self.verbose { |
66 | | - return tracing::level_filters::LevelFilter::DEBUG; |
| 77 | + use tracing::level_filters::LevelFilter; |
| 78 | + match self.verbose { |
| 79 | + 0 => LevelFilter::INFO, |
| 80 | + 1 => LevelFilter::DEBUG, |
| 81 | + _ => LevelFilter::TRACE, |
67 | 82 | } |
68 | | - tracing::level_filters::LevelFilter::INFO |
69 | 83 | } |
70 | 84 | } |
71 | 85 |
|
72 | 86 | #[cfg(not(target_arch = "wasm32"))] |
73 | 87 | impl From<Args> for azure_core_test::proxy::ProxyOptions { |
74 | 88 | fn from(args: Args) -> Self { |
75 | 89 | Self { |
| 90 | + auto: args.auto, |
76 | 91 | insecure: args.insecure, |
77 | 92 | auto_shutdown_in_seconds: args.auto_shutdown_in_seconds, |
78 | 93 | } |
|
0 commit comments