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

restart command

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