Skip to content

Commit

Permalink
ref(core): use const for command string name
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Apr 18, 2022
1 parent af1a390 commit 08d1aed
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/daemon/command.rs
Expand Up @@ -45,11 +45,11 @@ impl DaemonCommand {
let mut args = str.split(" ").collect::<Vec<&str>>();
let cmd = args.remove(0);
Ok(match cmd {
"build" => Self::Build(Build::new(args)?),
"run" => Self::Run(Run::new(args)?),
"rename_file" => Self::RenameFile(RenameFile::new(args)?),
"register" => Self::Register(Register::new(args)?),
"drop" => Self::Drop(Drop::new(args)?),
Build::KEY => Self::Build(Build::new(args)?),
Run::KEY => Self::Run(Run::new(args)?),
RenameFile::KEY => Self::RenameFile(RenameFile::new(args)?),
Register::KEY => Self::Register(Register::new(args)?),
Drop::KEY => Self::Drop(Drop::new(args)?),
_ => anyhow::bail!("Unknown command messsage: {cmd}"),
})
}
Expand Down
1 change: 1 addition & 0 deletions src/daemon/command/build.rs
Expand Up @@ -10,6 +10,7 @@ pub struct Build {
}

impl Build {
pub const KEY: &'static str = "build";
pub fn new(_args: Vec<&str>) -> Result<Build> {
Ok(Self {
target: None,
Expand Down
3 changes: 2 additions & 1 deletion src/daemon/command/drop.rs
Expand Up @@ -8,6 +8,7 @@ pub struct Drop {
}

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

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

#[cfg(feature = "lua")]
Expand Down
1 change: 1 addition & 0 deletions src/daemon/command/register.rs
Expand Up @@ -8,6 +8,7 @@ pub struct Register {
}

impl Register {
pub const KEY: &'static str = "register";
pub fn new(args: Vec<&str>) -> Result<Self> {
let pid = args.get(0);
let root = args.get(1);
Expand Down
3 changes: 2 additions & 1 deletion src/daemon/command/rename_file.rs
Expand Up @@ -9,6 +9,7 @@ pub struct RenameFile {
}

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

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

#[cfg(feature = "lua")]
Expand Down
1 change: 1 addition & 0 deletions src/daemon/command/run.rs
Expand Up @@ -7,6 +7,7 @@ pub struct Run {
}

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

0 comments on commit 08d1aed

Please sign in to comment.