提交 f3b80c42 authored 作者: Serhij S's avatar Serhij S

restart command

上级 9e40ef09
...@@ -37,6 +37,11 @@ pub enum SubCommand { ...@@ -37,6 +37,11 @@ pub enum SubCommand {
Config, Config,
#[clap(name = "run", about = "Switch remote into RUN mode")] #[clap(name = "run", about = "Switch remote into RUN mode")]
Run, Run,
#[clap(
name = "restart",
about = "Restart program (switch to CONFIG and back to RUN)"
)]
Restart,
#[clap(name = "flash", about = "Flash program")] #[clap(name = "flash", about = "Flash program")]
Flash(FlashCommand), Flash(FlashCommand),
#[clap(name = "purge", about = "Purge program data directory")] #[clap(name = "purge", about = "Purge program data directory")]
......
...@@ -82,10 +82,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -82,10 +82,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
remote::stat(&url, &key, agent)?; remote::stat(&url, &key, agent)?;
} }
SubCommand::Config => { SubCommand::Config => {
remote::set_mode(&url, &key, agent, Mode::Config)?; remote::set_mode(&url, &key, &agent, Mode::Config, true)?;
} }
SubCommand::Run => { SubCommand::Run => {
remote::set_mode(&url, &key, agent, Mode::Run)?; remote::set_mode(&url, &key, &agent, Mode::Run, true)?;
}
SubCommand::Restart => {
remote::set_mode(&url, &key, &agent, Mode::Config, false)?;
remote::set_mode(&url, &key, &agent, Mode::Run, true)?;
} }
SubCommand::Flash(opts) => { SubCommand::Flash(opts) => {
flashing::flash(&url, &key, agent, opts, build_config.unwrap_or_default())?; flashing::flash(&url, &key, agent, opts, build_config.unwrap_or_default())?;
......
...@@ -20,8 +20,9 @@ pub fn stat(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error ...@@ -20,8 +20,9 @@ pub fn stat(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error
pub fn set_mode( pub fn set_mode(
url: &str, url: &str,
key: &str, key: &str,
agent: Agent, agent: &Agent,
mode: Mode, mode: Mode,
report: bool,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
agent agent
.post(&format!("{}{}/set.program.mode", url, API_PREFIX)) .post(&format!("{}{}/set.program.mode", url, API_PREFIX))
...@@ -30,7 +31,10 @@ pub fn set_mode( ...@@ -30,7 +31,10 @@ pub fn set_mode(
"mode": mode, "mode": mode,
})) }))
.process_error()?; .process_error()?;
report_ok() if report {
report_ok()?;
}
Ok(())
} }
pub fn purge(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error::Error>> { pub fn purge(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error::Error>> {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论