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

purge command

上级 e8f38f02
...@@ -67,13 +67,15 @@ struct Args { ...@@ -67,13 +67,15 @@ struct Args {
#[derive(Parser)] #[derive(Parser)]
enum SubCommand { enum SubCommand {
#[clap(name = "stat", about = "Get program status")] #[clap(name = "stat", about = "Get program status")]
Stat(StatCommand), Stat,
#[clap(name = "config", about = "Put remote in CONFIG mode")] #[clap(name = "config", about = "Put remote in CONFIG mode")]
Config, Config,
#[clap(name = "run", about = "Put remote in RUN mode")] #[clap(name = "run", about = "Put remote in RUN mode")]
Run, Run,
#[clap(name = "flash", about = "Flash program")] #[clap(name = "flash", about = "Flash program")]
Flash(FlashCommand), Flash(FlashCommand),
#[clap(name = "purge", about = "Purge var directory")]
Purge,
} }
#[derive(Parser)] #[derive(Parser)]
...@@ -90,12 +92,7 @@ struct FlashCommand { ...@@ -90,12 +92,7 @@ struct FlashCommand {
run: bool, run: bool,
} }
fn stat_command( fn stat_command(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error::Error>> {
url: &str,
key: &str,
agent: Agent,
_opts: StatCommand,
) -> Result<(), Box<dyn std::error::Error>> {
let resp = agent let resp = agent
.post(&format!("{}{}/query.stats.program", url, API_PREFIX)) .post(&format!("{}{}/query.stats.program", url, API_PREFIX))
.set("x-auth-key", key) .set("x-auth-key", key)
...@@ -143,6 +140,16 @@ fn set_mode_command( ...@@ -143,6 +140,16 @@ fn set_mode_command(
Ok(()) Ok(())
} }
fn purge_command(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error::Error>> {
agent
.post(&format!("{}{}/purge.var", url, API_PREFIX))
.set("x-auth-key", key)
.call()
.process_error()?;
ok!();
Ok(())
}
#[derive(Deserialize)] #[derive(Deserialize)]
struct KernelInfo { struct KernelInfo {
machine: String, machine: String,
...@@ -271,9 +278,6 @@ fn find_name_and_chdir() -> Option<String> { ...@@ -271,9 +278,6 @@ fn find_name_and_chdir() -> Option<String> {
None None
} }
#[derive(Parser)]
struct StatCommand {}
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse(); let args = Args::parse();
let agent: Agent = ureq::AgentBuilder::new() let agent: Agent = ureq::AgentBuilder::new()
...@@ -281,8 +285,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -281,8 +285,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.timeout_write(Duration::from_secs_f64(args.timeout)) .timeout_write(Duration::from_secs_f64(args.timeout))
.build(); .build();
match args.subcmd { match args.subcmd {
SubCommand::Stat(opts) => { SubCommand::Stat => {
stat_command(&args.url, &args.key, agent, opts)?; stat_command(&args.url, &args.key, agent)?;
} }
SubCommand::Config => { SubCommand::Config => {
set_mode_command(&args.url, &args.key, agent, Mode::Config)?; set_mode_command(&args.url, &args.key, agent, Mode::Config)?;
...@@ -293,6 +297,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -293,6 +297,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
SubCommand::Flash(opts) => { SubCommand::Flash(opts) => {
flash(&args.url, &args.key, agent, opts)?; flash(&args.url, &args.key, agent, opts)?;
} }
SubCommand::Purge => {
purge_command(&args.url, &args.key, agent)?;
}
} }
Ok(()) Ok(())
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论