Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
b78cf95f
提交
b78cf95f
authored
4月 04, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
purge command
上级
e8f38f02
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
12 行删除
+19
-12
main.rs
roboplc-cli/src/main.rs
+19
-12
没有找到文件。
roboplc-cli/src/main.rs
浏览文件 @
b78cf95f
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论