Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
2f66b5f3
提交
2f66b5f3
authored
1月 05, 2025
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rollback
上级
4263a94b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
74 行增加
和
2 行删除
+74
-2
arguments.rs
roboplc-cli/src/arguments.rs
+28
-0
flashing.rs
roboplc-cli/src/flashing.rs
+43
-2
main.rs
roboplc-cli/src/main.rs
+3
-0
没有找到文件。
roboplc-cli/src/arguments.rs
浏览文件 @
2f66b5f3
...
...
@@ -50,6 +50,11 @@ pub enum SubCommand {
)]
Exec
(
ExecCommand
),
#[clap(name
=
"purge"
,
about
=
"Purge program data directory"
)]
#[clap(
name
=
"rollback"
,
about
=
"Rollback to the previous program version (requires RoboPLC Pro)"
)]
Rollback
(
RollbackCommand
),
Purge
,
}
...
...
@@ -148,6 +153,8 @@ pub struct FlashCommand {
pub
run
:
bool
,
#[clap(long,
help
=
"Perform live update (requires RoboPLC Pro)"
)]
pub
live
:
bool
,
#[clap(long,
help
=
"Skip current program backup (RoboPLC Pro)"
)]
pub
skip_backup
:
bool
,
}
#[derive(Parser)]
...
...
@@ -180,6 +187,24 @@ pub struct ExecCommand {
pub
args
:
Vec
<
String
>
,
}
#[derive(Parser)]
pub
struct
RollbackCommand
{
#[clap(
short
=
'f'
,
long,
help
=
"Force flash (automatically put remote in CONFIG mode), for Docker: run privileged"
)]
pub
force
:
bool
,
#[clap(
short
=
'r'
,
long,
help
=
"Put remote in RUN mode after flashing, for Docker: run the container"
)]
pub
run
:
bool
,
#[clap(long,
help
=
"Perform live update (requires RoboPLC Pro)"
)]
pub
live
:
bool
,
}
pub
struct
FlashExec
{
pub
cargo
:
Option
<
PathBuf
>
,
pub
cargo_target
:
Option
<
String
>
,
...
...
@@ -188,6 +213,7 @@ pub struct FlashExec {
pub
force
:
bool
,
pub
run
:
bool
,
pub
live
:
bool
,
pub
skip_backup
:
bool
,
pub
program_args
:
Vec
<
String
>
,
pub
program_env
:
BTreeMap
<
String
,
String
>
,
}
...
...
@@ -202,6 +228,7 @@ impl From<FlashCommand> for FlashExec {
force
:
cmd
.force
,
run
:
cmd
.run
,
live
:
cmd
.live
,
skip_backup
:
cmd
.skip_backup
,
program_args
:
Vec
::
new
(),
program_env
:
BTreeMap
::
new
(),
}
...
...
@@ -231,6 +258,7 @@ impl From<ExecCommand> for FlashExec {
force
:
cmd
.force
,
run
:
false
,
live
:
false
,
skip_backup
:
false
,
program_args
:
cmd
.args
,
program_env
,
}
...
...
roboplc-cli/src/flashing.rs
浏览文件 @
2f66b5f3
...
...
@@ -11,7 +11,7 @@ use ureq_multipart::MultipartBuilder;
use
which
::
which
;
use
crate
::{
arguments
::
FlashExec
,
arguments
::
{
FlashExec
,
RollbackCommand
}
,
common
::{
report_ok
,
KernelInfo
},
config
,
ureq_err
::
PrintErr
,
...
...
@@ -27,6 +27,7 @@ fn flash_file(
force
:
bool
,
run
:
bool
,
live
:
bool
,
skip_backup
:
bool
,
exec_only
:
bool
,
program_args
:
Vec
<
String
>
,
program_env
:
BTreeMap
<
String
,
String
>
,
...
...
@@ -93,12 +94,19 @@ fn flash_file(
run
:
bool
,
#[serde(skip_serializing_if
=
"std::ops::Not::not"
)]
live
:
bool
,
#[serde(skip_serializing_if
=
"std::ops::Not::not"
)]
skip_backup
:
bool
,
}
let
(
content_type
,
data
)
=
MultipartBuilder
::
new
()
.add_file
(
"file"
,
file
)
?
.add_text
(
"params"
,
&
serde_json
::
to_string
(
&
Payload
{
force
,
run
,
live
})
?
,
&
serde_json
::
to_string
(
&
Payload
{
force
,
run
,
live
,
skip_backup
,
})
?
,
)
?
.finish
()
?
;
agent
...
...
@@ -111,6 +119,34 @@ fn flash_file(
Ok
(())
}
pub
fn
rollback
(
url
:
&
str
,
key
:
&
str
,
agent
:
Agent
,
opts
:
RollbackCommand
,
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
#[derive(Serialize)]
struct
Payload
{
#[serde(skip_serializing_if
=
"std::ops::Not::not"
)]
force
:
bool
,
#[serde(skip_serializing_if
=
"std::ops::Not::not"
)]
run
:
bool
,
#[serde(skip_serializing_if
=
"std::ops::Not::not"
)]
live
:
bool
,
}
agent
.post
(
&
format!
(
"{}{}/rollback"
,
url
,
API_PREFIX
))
.set
(
"x-auth-key"
,
key
)
.send_json
(
&
Payload
{
force
:
opts
.force
,
run
:
opts
.run
,
live
:
opts
.live
,
})
.process_error
()
?
;
report_ok
()
?
;
Ok
(())
}
#[allow(clippy
::
too_many_arguments,
clippy
::
fn_params_excessive_bools)]
fn
run_build_custom
(
url
:
&
str
,
...
...
@@ -119,6 +155,7 @@ fn run_build_custom(
force
:
bool
,
run
:
bool
,
live
:
bool
,
skip_backup
:
bool
,
cmd
:
&
str
,
file
:
&
Path
,
exec_only
:
bool
,
...
...
@@ -147,6 +184,7 @@ fn run_build_custom(
force
,
run
,
live
,
skip_backup
,
exec_only
,
program_args
,
program_env
,
...
...
@@ -173,6 +211,7 @@ pub fn flash(
opts
.force
,
opts
.run
,
opts
.live
,
opts
.skip_backup
,
exec_only
,
opts
.program_args
,
opts
.program_env
,
...
...
@@ -185,6 +224,7 @@ pub fn flash(
opts
.force
,
opts
.run
,
opts
.live
,
opts
.skip_backup
,
&
custom_cmd
,
&
build_custom
.file
...
...
@@ -265,6 +305,7 @@ pub fn flash(
opts
.force
,
opts
.run
,
opts
.live
,
opts
.skip_backup
,
exec_only
,
opts
.program_args
,
opts
.program_env
,
...
...
roboplc-cli/src/main.rs
浏览文件 @
2f66b5f3
...
...
@@ -126,6 +126,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
false
,
)
?
;
}
SubCommand
::
Rollback
(
opts
)
=>
{
flashing
::
rollback
(
&
url
,
&
key
,
agent
,
opts
)
?
;
}
SubCommand
::
Exec
(
opts
)
=>
{
flashing
::
flash
(
&
url
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论