Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
e731ccdd
提交
e731ccdd
authored
6月 18, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restart command and build-custom
上级
f3b80c42
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
71 行增加
和
4 行删除
+71
-4
common.rs
roboplc-cli/src/common.rs
+4
-0
config.rs
roboplc-cli/src/config.rs
+10
-0
flashing.rs
roboplc-cli/src/flashing.rs
+46
-3
main.rs
roboplc-cli/src/main.rs
+10
-1
project.rs
roboplc-cli/src/project.rs
+1
-0
没有找到文件。
roboplc-cli/src/common.rs
浏览文件 @
e731ccdd
...
@@ -81,6 +81,10 @@ pub fn find_robo_toml() -> Option<PathBuf> {
...
@@ -81,6 +81,10 @@ pub fn find_robo_toml() -> Option<PathBuf> {
}
}
}
}
if
!
current_dir
.pop
()
{
if
!
current_dir
.pop
()
{
let
local_path
=
PathBuf
::
from
(
CONFIG_FILE_NAME
);
if
local_path
.exists
()
{
return
Some
(
local_path
);
}
break
;
break
;
}
}
}
}
...
...
roboplc-cli/src/config.rs
浏览文件 @
e731ccdd
...
@@ -10,6 +10,8 @@ pub struct Config {
...
@@ -10,6 +10,8 @@ pub struct Config {
pub
remote
:
Remote
,
pub
remote
:
Remote
,
#[serde(default)]
#[serde(default)]
pub
build
:
Build
,
pub
build
:
Build
,
#[serde(default,
rename
=
"build-custom"
)]
pub
build_custom
:
BuildCustom
,
}
}
#[derive(Deserialize,
Serialize,
Default,
Debug)]
#[derive(Deserialize,
Serialize,
Default,
Debug)]
...
@@ -32,6 +34,14 @@ pub struct Build {
...
@@ -32,6 +34,14 @@ pub struct Build {
pub
cargo_args
:
Option
<
String
>
,
pub
cargo_args
:
Option
<
String
>
,
}
}
#[derive(Deserialize,
Serialize,
Default,
Debug)]
pub
struct
BuildCustom
{
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
command
:
Option
<
String
>
,
#[serde(skip_serializing_if
=
"Option::is_none"
)]
pub
file
:
Option
<
PathBuf
>
,
}
#[derive(Deserialize,
Debug)]
#[derive(Deserialize,
Debug)]
struct
GlobalConfig
{
struct
GlobalConfig
{
remote
:
BTreeMap
<
String
,
Remote
>
,
remote
:
BTreeMap
<
String
,
Remote
>
,
...
...
roboplc-cli/src/flashing.rs
浏览文件 @
e731ccdd
...
@@ -21,10 +21,13 @@ fn flash_file(
...
@@ -21,10 +21,13 @@ fn flash_file(
url
:
&
str
,
url
:
&
str
,
key
:
&
str
,
key
:
&
str
,
agent
:
Agent
,
agent
:
Agent
,
file
:
PathBuf
,
file
:
&
Path
,
force
:
bool
,
force
:
bool
,
run
:
bool
,
run
:
bool
,
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
if
!
file
.exists
()
{
return
Err
(
format!
(
"File not found: {}"
,
file
.display
())
.into
());
}
let
(
content_type
,
data
)
=
MultipartBuilder
::
new
()
let
(
content_type
,
data
)
=
MultipartBuilder
::
new
()
.add_file
(
"file"
,
file
)
?
.add_file
(
"file"
,
file
)
?
.add_text
(
.add_text
(
...
@@ -47,15 +50,55 @@ fn flash_file(
...
@@ -47,15 +50,55 @@ fn flash_file(
Ok
(())
Ok
(())
}
}
fn
run_build_custom
(
url
:
&
str
,
key
:
&
str
,
agent
:
Agent
,
force
:
bool
,
run
:
bool
,
cmd
:
&
str
,
file
:
&
Path
,
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
println!
(
"Remote: {}"
,
url
.yellow
());
println!
(
"Build command line: {}"
,
cmd
.yellow
());
println!
(
"Binary: {}"
,
file
.display
()
.to_string
()
.yellow
());
println!
(
"Compiling..."
);
let
result
=
std
::
process
::
Command
::
new
(
"sh"
)
.args
([
"-c"
,
cmd
])
.status
()
?
;
if
!
result
.success
()
{
return
Err
(
"Compilation failed"
.into
());
}
println!
(
"Flashing..."
);
if
!
file
.exists
()
{
return
Err
(
format!
(
"File not found: {}"
,
file
.display
())
.into
());
}
flash_file
(
url
,
key
,
agent
,
file
,
force
,
run
)
?
;
Ok
(())
}
pub
fn
flash
(
pub
fn
flash
(
url
:
&
str
,
url
:
&
str
,
key
:
&
str
,
key
:
&
str
,
agent
:
Agent
,
agent
:
Agent
,
opts
:
FlashCommand
,
opts
:
FlashCommand
,
build_config
:
config
::
Build
,
build_config
:
config
::
Build
,
build_custom
:
config
::
BuildCustom
,
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
if
let
Some
(
file
)
=
opts
.file
{
if
let
Some
(
file
)
=
opts
.file
{
flash_file
(
url
,
key
,
agent
,
file
,
opts
.force
,
opts
.run
)
?
;
flash_file
(
url
,
key
,
agent
,
&
file
,
opts
.force
,
opts
.run
)
?
;
}
else
if
let
Some
(
custom_cmd
)
=
build_custom
.command
{
run_build_custom
(
url
,
key
,
agent
,
opts
.force
,
opts
.run
,
&
custom_cmd
,
&
build_custom
.file
.ok_or
(
"Custom build command requires a file"
)
?
,
)
?
;
}
else
{
}
else
{
let
mut
cargo_target
:
Option
<
String
>
=
None
;
let
mut
cargo_target
:
Option
<
String
>
=
None
;
if
let
Some
(
c
)
=
opts
.cargo_target
{
if
let
Some
(
c
)
=
opts
.cargo_target
{
...
@@ -120,7 +163,7 @@ pub fn flash(
...
@@ -120,7 +163,7 @@ pub fn flash(
return
Err
(
"Compilation failed"
.into
());
return
Err
(
"Compilation failed"
.into
());
}
}
println!
(
"Flashing..."
);
println!
(
"Flashing..."
);
flash_file
(
url
,
key
,
agent
,
binary_name
,
opts
.force
,
opts
.run
)
?
;
flash_file
(
url
,
key
,
agent
,
&
binary_name
,
opts
.force
,
opts
.run
)
?
;
}
}
report_ok
()
report_ok
()
}
}
...
...
roboplc-cli/src/main.rs
浏览文件 @
e731ccdd
...
@@ -40,6 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
...
@@ -40,6 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
let
mut
maybe_timeout
=
args
.timeout
;
let
mut
maybe_timeout
=
args
.timeout
;
let
mut
build_config
=
None
;
let
mut
build_config
=
None
;
let
mut
build_custom
=
None
;
if
let
SubCommand
::
New
(
_
)
=
args
.subcmd
{
if
let
SubCommand
::
New
(
_
)
=
args
.subcmd
{
// do not parse robo.toml for `new` command
// do not parse robo.toml for `new` command
}
else
if
let
Some
(
robo_toml_path
)
=
find_robo_toml
()
{
}
else
if
let
Some
(
robo_toml_path
)
=
find_robo_toml
()
{
...
@@ -55,6 +56,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
...
@@ -55,6 +56,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
maybe_timeout
=
robo_toml
.remote.timeout
;
maybe_timeout
=
robo_toml
.remote.timeout
;
}
}
build_config
=
Some
(
robo_toml
.build
);
build_config
=
Some
(
robo_toml
.build
);
build_custom
=
Some
(
robo_toml
.build_custom
);
}
}
maybe_url
=
maybe_url
.map
(|
v
|
{
maybe_url
=
maybe_url
.map
(|
v
|
{
let
mut
u
=
v
.trim_end_matches
(
'/'
)
.to_owned
();
let
mut
u
=
v
.trim_end_matches
(
'/'
)
.to_owned
();
...
@@ -92,7 +94,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
...
@@ -92,7 +94,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
remote
::
set_mode
(
&
url
,
&
key
,
&
agent
,
Mode
::
Run
,
true
)
?
;
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
(),
build_custom
.unwrap_or_default
(),
)
?
;
}
}
SubCommand
::
Purge
=>
{
SubCommand
::
Purge
=>
{
remote
::
purge
(
&
url
,
&
key
,
agent
)
?
;
remote
::
purge
(
&
url
,
&
key
,
agent
)
?
;
...
...
roboplc-cli/src/project.rs
浏览文件 @
e731ccdd
...
@@ -43,6 +43,7 @@ pub fn create(
...
@@ -43,6 +43,7 @@ pub fn create(
timeout
:
maybe_timeout
,
timeout
:
maybe_timeout
,
},
},
build
:
<
_
>
::
default
(),
build
:
<
_
>
::
default
(),
build_custom
:
<
_
>
::
default
(),
};
};
std
::
fs
::
write
(
CONFIG_FILE_NAME
,
toml
::
to_string_pretty
(
&
robo_toml
)
?
)
?
;
std
::
fs
::
write
(
CONFIG_FILE_NAME
,
toml
::
to_string_pretty
(
&
robo_toml
)
?
)
?
;
std
::
fs
::
write
(
"src/main.rs"
,
prepare_main
(
TPL_DEFAULT_RS
,
&
robo_features
))
?
;
std
::
fs
::
write
(
"src/main.rs"
,
prepare_main
(
TPL_DEFAULT_RS
,
&
robo_features
))
?
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论