Skip to content

Commit 08d1aed

Browse files
committed
ref(core): use const for command string name
1 parent af1a390 commit 08d1aed

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

src/daemon/command.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ impl DaemonCommand {
4545
let mut args = str.split(" ").collect::<Vec<&str>>();
4646
let cmd = args.remove(0);
4747
Ok(match cmd {
48-
"build" => Self::Build(Build::new(args)?),
49-
"run" => Self::Run(Run::new(args)?),
50-
"rename_file" => Self::RenameFile(RenameFile::new(args)?),
51-
"register" => Self::Register(Register::new(args)?),
52-
"drop" => Self::Drop(Drop::new(args)?),
48+
Build::KEY => Self::Build(Build::new(args)?),
49+
Run::KEY => Self::Run(Run::new(args)?),
50+
RenameFile::KEY => Self::RenameFile(RenameFile::new(args)?),
51+
Register::KEY => Self::Register(Register::new(args)?),
52+
Drop::KEY => Self::Drop(Drop::new(args)?),
5353
_ => anyhow::bail!("Unknown command messsage: {cmd}"),
5454
})
5555
}

src/daemon/command/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Build {
1010
}
1111

1212
impl Build {
13+
pub const KEY: &'static str = "build";
1314
pub fn new(_args: Vec<&str>) -> Result<Build> {
1415
Ok(Self {
1516
target: None,

src/daemon/command/drop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct Drop {
88
}
99

1010
impl Drop {
11+
pub const KEY: &'static str = "drop";
1112
pub fn new(args: Vec<&str>) -> Result<Self> {
1213
let pid = args.get(0);
1314
let root = args.get(1);
@@ -23,7 +24,7 @@ impl Drop {
2324
}
2425

2526
pub fn request(pid: i32, root: String) -> Result<()> {
26-
crate::Daemon::execute(&["drop", pid.to_string().as_str(), root.as_str()])
27+
crate::Daemon::execute(&[Self::KEY, pid.to_string().as_str(), root.as_str()])
2728
}
2829

2930
#[cfg(feature = "lua")]

src/daemon/command/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct Register {
88
}
99

1010
impl Register {
11+
pub const KEY: &'static str = "register";
1112
pub fn new(args: Vec<&str>) -> Result<Self> {
1213
let pid = args.get(0);
1314
let root = args.get(1);

src/daemon/command/rename_file.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct RenameFile {
99
}
1010

1111
impl RenameFile {
12+
pub const KEY: &'static str = "rename_file";
1213
pub fn new(args: Vec<&str>) -> Result<Self> {
1314
let path = args.get(0);
1415
let new_name = args.get(2);
@@ -30,7 +31,7 @@ impl RenameFile {
3031
}
3132

3233
pub fn request(path: &str, name: &str, new_name: &str) -> Result<()> {
33-
crate::Daemon::execute(&["rename_file", path, name, new_name])
34+
crate::Daemon::execute(&[Self::KEY, path, name, new_name])
3435
}
3536

3637
#[cfg(feature = "lua")]

src/daemon/command/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Run {
77
}
88

99
impl Run {
10+
pub const KEY: &'static str = "run";
1011
pub fn new(args: Vec<&str>) -> Result<Self> {
1112
let _simulator = args.get(0).unwrap_or(&"").parse::<bool>().unwrap_or(false);
1213
Ok(Self { _simulator })

0 commit comments

Comments
 (0)