Skip to content

Commit 59c72c6

Browse files
Updated 'test-services' to remove 'clap-v2'
Signed-off-by: Abhijit Gadgil <agadgil@progress.com>
1 parent 2849105 commit 59c72c6

3 files changed

Lines changed: 33 additions & 30 deletions

File tree

test-services/test-probe/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ workspace = "../../"
88
[dependencies]
99
actix-rt = "*"
1010
actix-web = { version = "*", default-features = false, features = [ "rustls-0_21" ] }
11-
clap = { git = "https://github.com/habitat-sh/clap.git", branch = "v2-master", features = [ "suggestions", "color", "unstable" ] }
11+
clap = { version = "4", features = ["env", "derive", "string", "wrap_help"] }
1212
serde = { version = "*", features = ["derive"] }
1313
serde_json = "*"
1414
toml = "*"

test-services/test-probe/src/config.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
use crate::error::{Error,
2-
Result};
1+
use crate::error::{Error, Result};
32
use clap::ArgMatches;
4-
use serde::{Deserialize,
5-
Serialize};
6-
use std::{fs,
7-
path::PathBuf};
3+
use serde::{Deserialize, Serialize};
4+
use std::{fs, path::PathBuf};
85

96
pub const DEFAULT_JSON_SOURCE: &str = "/hab/svc/test-probe/config/render_context_file.json";
107
pub const DEFAULT_HOST: &str = "0.0.0.0";
118
pub const DEFAULT_PORT: u16 = 8000;
129

1310
#[derive(Clone, Debug, Deserialize, Serialize)]
1411
pub struct Config {
15-
pub host: String,
16-
pub port: u16,
12+
pub host: String,
13+
pub port: u16,
1714
pub render_context_file: PathBuf,
1815
}
1916

2017
impl Default for Config {
2118
fn default() -> Self {
22-
Config { host: DEFAULT_HOST.to_string(),
23-
port: DEFAULT_PORT,
24-
render_context_file: PathBuf::from(DEFAULT_JSON_SOURCE), }
19+
Config {
20+
host: DEFAULT_HOST.to_string(),
21+
port: DEFAULT_PORT,
22+
render_context_file: PathBuf::from(DEFAULT_JSON_SOURCE),
23+
}
2524
}
2625
}
2726

2827
pub fn from_matches(args: &ArgMatches) -> Result<Config> {
29-
if let Some(path) = args.value_of("config") {
28+
if let Some(path) = args.get_one::<String>("config") {
3029
let contents = fs::read_to_string(path)?;
3130
toml::from_str(&contents).map_err(Error::Toml)
3231
} else {

test-services/test-probe/src/main.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
use actix_web::{web::{self,
2-
Data},
3-
App as ActixApp,
4-
HttpServer};
5-
use clap::{App,
6-
Arg};
1+
use actix_web::{
2+
web::{self, Data},
3+
App as ActixApp, HttpServer,
4+
};
5+
use clap::{Arg, Command};
76

87
mod config;
98
mod context;
109
mod error;
1110

12-
fn app<'a, 'b>() -> App<'a, 'b> {
13-
App::new("test-probe").arg(Arg::with_name("config").short("c")
14-
.long("config")
15-
.value_name("CONFIG")
16-
.help("Sets a custom config file")
17-
.takes_value(true))
11+
fn app() -> Command {
12+
Command::new("test-probe").arg(
13+
Arg::new("config")
14+
.short('c')
15+
.long("config")
16+
.value_name("CONFIG")
17+
.help("Sets a custom config file")
18+
.num_args(1),
19+
)
1820
}
1921

2022
#[actix_rt::main]
@@ -23,11 +25,13 @@ async fn main() -> std::io::Result<()> {
2325
let config = config::from_matches(&matches).expect("Could not create application");
2426
let bind_addr = format!("{}:{}", config.host, config.port);
2527
let server = HttpServer::new(move || {
26-
ActixApp::new().app_data(Data::new(config.clone()))
27-
.route("context", web::get().to(context::show))
28-
.route("context/{path:.*}", web::get().to(context::show))
29-
}).workers(1)
30-
.bind(&bind_addr)?;
28+
ActixApp::new()
29+
.app_data(Data::new(config.clone()))
30+
.route("context", web::get().to(context::show))
31+
.route("context/{path:.*}", web::get().to(context::show))
32+
})
33+
.workers(1)
34+
.bind(&bind_addr)?;
3135

3236
println!("Starting test-probe on {}", bind_addr);
3337
server.run().await

0 commit comments

Comments
 (0)