Skip to content

Commit 893d5aa

Browse files
David Tolnaymeta-codesync[bot]
authored andcommitted
Update from clap 2 to 4
Summary: ```lang=log The SCM Daemon is a program to speed up and facilitate mercurial commands and extensions The SCM Daemon runs as a service, logging its operations directly into stdout, and init systems like systemd or launchd will automatically handle everything else, including startup, shutdown, logging redirection, lifecycle management etc. Usage: scm_daemon [OPTIONS] --config <CONFIG> Options: --config <CONFIG> Config file (toml format) --pidfile <PIDFILE> Specify path to pidfile -h, --help Print help (see a summary with '-h') -V, --version Print version ``` Reviewed By: diliop Differential Revision: D104272409 fbshipit-source-id: f8e0c7f322b7866e2e43bfb688133a9af42798f7
1 parent 8b11186 commit 893d5aa

3 files changed

Lines changed: 30 additions & 26 deletions

File tree

eden/scm/exec/scm_daemon/BUCK

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rust_binary(
1414
link_style = "static",
1515
deps = [
1616
"fbsource//third-party/rust:anyhow",
17-
"fbsource//third-party/rust:clap-2",
17+
"fbsource//third-party/rust:clap",
1818
"fbsource//third-party/rust:env_logger",
1919
"fbsource//third-party/rust:log",
2020
"fbsource//third-party/rust:serde",

eden/scm/exec/scm_daemon/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024"
77

88
[dependencies]
99
anyhow = "1.0.102"
10-
clap = "2.34.0"
10+
clap = { version = "4.6.0", features = ["derive", "env", "string", "unicode", "wrap_help"] }
1111
env_logger = { version = "0.11.10", features = ["color"] }
1212
log = { version = "0.4.29", features = ["kv_unstable", "kv_unstable_std"] }
1313
sapling-commitcloudsubscriber = { version = "0.1.0", path = "../../lib/commitcloudsubscriber" }

eden/scm/exec/scm_daemon/src/main.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,38 @@ use std::fs::File;
1111
use std::io::Read;
1212
#[cfg(target_os = "macos")]
1313
use std::io::Write;
14+
use std::path::PathBuf;
1415

1516
use anyhow::Context;
1617
use anyhow::Result;
1718
use anyhow::anyhow;
1819
use anyhow::bail;
19-
use clap::App;
20-
use clap::Arg;
20+
use clap::Parser;
2121
use commitcloudsubscriber::CommitCloudConfig;
2222
use commitcloudsubscriber::CommitCloudTcpReceiverService;
2323
use commitcloudsubscriber::CommitCloudWorkspaceSubscriberService;
2424
use log::info;
2525
use serde::Deserialize;
2626

27+
/// The SCM Daemon is a program to speed up and facilitate mercurial commands
28+
/// and extensions
29+
///
30+
/// The SCM Daemon runs as a service, logging its operations directly into
31+
/// stdout, and init systems like systemd or launchd will automatically handle
32+
/// everything else, including startup, shutdown, logging redirection, lifecycle
33+
/// management etc.
34+
#[derive(Parser)]
35+
#[command(name = "SCM Daemon", version = "1.0.0")]
36+
struct Args {
37+
/// Config file (toml format)
38+
#[arg(long)]
39+
config: PathBuf,
40+
41+
/// Specify path to pidfile
42+
#[arg(long)]
43+
pidfile: Option<PathBuf>,
44+
}
45+
2746
/// This is what we're going to decode toml config into.
2847
/// Each field is optional, meaning that it doesn't have to be present in TOML.
2948
#[derive(Debug, Deserialize)]
@@ -37,42 +56,27 @@ pub struct Config {
3756
async fn main() -> Result<()> {
3857
check_nice()?;
3958
env_logger::init();
40-
let help: &str = &format!(
41-
"{}\n{}",
42-
"The SCM Daemon is a program to speed up and facilitate mercurial commands and extensions",
43-
"The SCM Daemon runs as a service, logging its operations directly into stdout, \
44-
and init systems like systemd or launchd will automatically handle everything else, \
45-
including startup, shutdown, logging redirection, lifecycle management etc.",
46-
);
47-
48-
let matches = App::new("SCM Daemon")
49-
.version("1.0.0")
50-
.help(help)
51-
.args(&[
52-
Arg::from_usage("--config [config file (toml format)]").required(true),
53-
Arg::from_usage("--pidfile [specify path to pidfile]").required(false),
54-
])
55-
.get_matches();
59+
let args = Args::parse();
5660

5761
// write pidfile
5862
// do not rely on existence of this file to check if program running
5963
// std::process::id unstable feature for old compiler
6064
// so add #[cfg(target_os = "macos")] temporary
6165
#[cfg(target_os = "macos")]
6266
{
63-
if let Some(path) = matches.value_of("pidfile") {
67+
if let Some(path) = args.pidfile {
6468
File::create(path)?.write_fmt(format_args!("{}", std::process::id()))?;
6569
}
6670
}
6771

68-
// read required config path
69-
let configfile = matches.value_of("config").unwrap();
70-
71-
info!("Reading Scm Daemon configuration from {}", configfile);
72+
info!(
73+
"Reading Scm Daemon configuration from {}",
74+
args.config.display(),
75+
);
7276

7377
// parse the toml config
7478
let config: Config = toml::from_str(&{
75-
let mut f = File::open(configfile)?;
79+
let mut f = File::open(args.config)?;
7680
let mut content = String::new();
7781
f.read_to_string(&mut content)?;
7882
content

0 commit comments

Comments
 (0)