Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
0859adaf
提交
0859adaf
authored
4月 04, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get from config
上级
a3410096
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
73 行增加
和
18 行删除
+73
-18
Cargo.lock
roboplc-cli/Cargo.lock
+1
-1
Cargo.toml
roboplc-cli/Cargo.toml
+1
-1
main.rs
roboplc-cli/src/main.rs
+71
-16
没有找到文件。
roboplc-cli/Cargo.lock
浏览文件 @
0859adaf
...
@@ -1030,7 +1030,7 @@ dependencies = [
...
@@ -1030,7 +1030,7 @@ dependencies = [
[[package]]
[[package]]
name = "roboplc-cli"
name = "roboplc-cli"
version = "0.1.
0
"
version = "0.1.
1
"
dependencies = [
dependencies = [
"clap",
"clap",
"colored",
"colored",
...
...
roboplc-cli/Cargo.toml
浏览文件 @
0859adaf
[package]
[package]
name
=
"roboplc-cli"
name
=
"roboplc-cli"
version
=
"0.1.
1
"
version
=
"0.1.
2
"
edition
=
"2021"
edition
=
"2021"
authors
=
[
"Serhij S. <div@altertech.com>"
]
authors
=
[
"Serhij S. <div@altertech.com>"
]
license
=
"Apache-2.0"
license
=
"Apache-2.0"
...
...
roboplc-cli/src/main.rs
浏览文件 @
0859adaf
use
core
::
fmt
;
use
core
::
fmt
;
use
std
::{
use
std
::{
env
,
env
,
fs
,
path
::{
Path
,
PathBuf
},
path
::{
Path
,
PathBuf
},
time
::
Duration
,
time
::
Duration
,
};
};
...
@@ -16,6 +16,8 @@ use which::which;
...
@@ -16,6 +16,8 @@ use which::which;
const
API_PREFIX
:
&
str
=
"/roboplc/api"
;
const
API_PREFIX
:
&
str
=
"/roboplc/api"
;
const
DEFAULT_TIMEOUT
:
u64
=
60
;
#[derive(Debug,
Serialize,
Deserialize)]
#[derive(Debug,
Serialize,
Deserialize)]
pub
struct
State
{
pub
struct
State
{
pid
:
Option
<
u32
>
,
pid
:
Option
<
u32
>
,
...
@@ -54,12 +56,12 @@ pub struct Task {
...
@@ -54,12 +56,12 @@ pub struct Task {
#[derive(Parser)]
#[derive(Parser)]
struct
Args
{
struct
Args
{
#[clap(short
=
'T'
,
long,
default_value
=
"60"
,
help
=
"Manager API timeout"
)]
#[clap(short
=
'T'
,
long,
help
=
"Manager API timeout"
)]
timeout
:
f64
,
timeout
:
Option
<
u64
>
,
#[clap(short
=
'U'
,
long,
env
=
"ROBOPLC_URL"
,
help
=
"Manager URL"
)]
#[clap(short
=
'U'
,
long,
env
=
"ROBOPLC_URL"
,
help
=
"Manager URL"
)]
url
:
String
,
url
:
Option
<
String
>
,
#[clap(short
=
'k'
,
long,
env
=
"ROBOPLC_KEY"
,
help
=
"Management key"
)]
#[clap(short
=
'k'
,
long,
env
=
"ROBOPLC_KEY"
,
help
=
"Management key"
)]
key
:
String
,
key
:
Option
<
String
>
,
#[clap(subcommand)]
#[clap(subcommand)]
subcmd
:
SubCommand
,
subcmd
:
SubCommand
,
}
}
...
@@ -74,7 +76,7 @@ enum SubCommand {
...
@@ -74,7 +76,7 @@ enum SubCommand {
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"
)]
#[clap(name
=
"purge"
,
about
=
"Purge
program data
directory"
)]
Purge
,
Purge
,
}
}
...
@@ -142,7 +144,7 @@ fn set_mode_command(
...
@@ -142,7 +144,7 @@ fn set_mode_command(
fn
purge_command
(
url
:
&
str
,
key
:
&
str
,
agent
:
Agent
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
fn
purge_command
(
url
:
&
str
,
key
:
&
str
,
agent
:
Agent
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
agent
agent
.post
(
&
format!
(
"{}{}/purge.
var
"
,
url
,
API_PREFIX
))
.post
(
&
format!
(
"{}{}/purge.
program.data
"
,
url
,
API_PREFIX
))
.set
(
"x-auth-key"
,
key
)
.set
(
"x-auth-key"
,
key
)
.call
()
.call
()
.process_error
()
?
;
.process_error
()
?
;
...
@@ -267,11 +269,31 @@ fn find_name_and_chdir() -> Option<String> {
...
@@ -267,11 +269,31 @@ fn find_name_and_chdir() -> Option<String> {
let
mut
cargo_toml_path
=
current_dir
.clone
();
let
mut
cargo_toml_path
=
current_dir
.clone
();
cargo_toml_path
.push
(
"Cargo.toml"
);
cargo_toml_path
.push
(
"Cargo.toml"
);
if
cargo_toml_path
.exists
()
{
if
cargo_toml_path
.exists
()
{
let
contents
=
std
::
fs
::
read_to_string
(
cargo_toml_path
)
.ok
()
?
;
let
contents
=
fs
::
read_to_string
(
cargo_toml_path
)
.ok
()
?
;
let
value
=
contents
.parse
::
<
toml
::
Value
>
()
.ok
()
?
;
let
value
=
contents
.parse
::
<
toml
::
Value
>
()
.ok
()
?
;
env
::
set_current_dir
(
current_dir
)
.ok
()
?
;
env
::
set_current_dir
(
current_dir
)
.ok
()
?
;
return
value
[
"package"
][
"name"
]
.as_str
()
.map
(
String
::
from
);
return
value
[
"package"
][
"name"
]
.as_str
()
.map
(
String
::
from
);
}
else
if
!
current_dir
.pop
()
{
}
if
!
current_dir
.pop
()
{
break
;
}
}
None
}
fn
find_roboplc_toml
()
->
Option
<
PathBuf
>
{
let
mut
current_dir
=
env
::
current_dir
()
.ok
()
?
;
loop
{
let
mut
cargo_toml_path
=
current_dir
.clone
();
cargo_toml_path
.push
(
"Cargo.toml"
);
if
cargo_toml_path
.exists
()
{
let
mut
roboplc_toml_path
=
current_dir
.clone
();
roboplc_toml_path
.push
(
"robo.toml"
);
if
roboplc_toml_path
.exists
()
{
return
Some
(
roboplc_toml_path
);
}
}
if
!
current_dir
.pop
()
{
break
;
break
;
}
}
}
}
...
@@ -280,25 +302,58 @@ fn find_name_and_chdir() -> Option<String> {
...
@@ -280,25 +302,58 @@ fn find_name_and_chdir() -> Option<String> {
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
mut
url
=
args
.url
;
let
mut
key
=
args
.key
;
let
mut
timeout
=
args
.timeout
;
if
let
Some
(
roboplc_toml_path
)
=
find_roboplc_toml
()
{
let
contents
=
fs
::
read_to_string
(
roboplc_toml_path
)
?
;
let
value
=
contents
.parse
::
<
toml
::
Value
>
()
?
;
if
url
.is_none
()
{
url
=
value
.get
(
"remote"
)
.and_then
(|
v
|
v
.get
(
"url"
))
.and_then
(|
v
|
v
.as_str
())
.map
(
String
::
from
);
}
if
key
.is_none
()
{
key
=
value
.get
(
"remote"
)
.and_then
(|
v
|
v
.get
(
"key"
))
.and_then
(|
v
|
v
.as_str
())
.map
(
String
::
from
);
}
if
timeout
.is_none
()
{
timeout
=
Some
(
u64
::
try_from
(
value
.get
(
"remote"
)
.and_then
(|
v
|
v
.get
(
"timeout"
))
.and_then
(|
v
|
v
.as_integer
())
.ok_or
(
"Invalid timeout (must be integer)"
)
?
,
)
?
);
}
}
let
timeout
=
timeout
.unwrap_or
(
DEFAULT_TIMEOUT
);
let
url
=
url
.ok_or
(
"URL not specified"
)
?
;
let
key
=
key
.ok_or
(
"Key not specified"
)
?
;
let
agent
:
Agent
=
ureq
::
AgentBuilder
::
new
()
let
agent
:
Agent
=
ureq
::
AgentBuilder
::
new
()
.timeout_read
(
Duration
::
from_secs
_f64
(
args
.
timeout
))
.timeout_read
(
Duration
::
from_secs
(
timeout
))
.timeout_write
(
Duration
::
from_secs
_f64
(
args
.
timeout
))
.timeout_write
(
Duration
::
from_secs
(
timeout
))
.build
();
.build
();
match
args
.subcmd
{
match
args
.subcmd
{
SubCommand
::
Stat
=>
{
SubCommand
::
Stat
=>
{
stat_command
(
&
args
.url
,
&
args
.
key
,
agent
)
?
;
stat_command
(
&
url
,
&
key
,
agent
)
?
;
}
}
SubCommand
::
Config
=>
{
SubCommand
::
Config
=>
{
set_mode_command
(
&
args
.url
,
&
args
.
key
,
agent
,
Mode
::
Config
)
?
;
set_mode_command
(
&
url
,
&
key
,
agent
,
Mode
::
Config
)
?
;
}
}
SubCommand
::
Run
=>
{
SubCommand
::
Run
=>
{
set_mode_command
(
&
args
.url
,
&
args
.
key
,
agent
,
Mode
::
Run
)
?
;
set_mode_command
(
&
url
,
&
key
,
agent
,
Mode
::
Run
)
?
;
}
}
SubCommand
::
Flash
(
opts
)
=>
{
SubCommand
::
Flash
(
opts
)
=>
{
flash
(
&
args
.url
,
&
args
.
key
,
agent
,
opts
)
?
;
flash
(
&
url
,
&
key
,
agent
,
opts
)
?
;
}
}
SubCommand
::
Purge
=>
{
SubCommand
::
Purge
=>
{
purge_command
(
&
args
.url
,
&
args
.
key
,
agent
)
?
;
purge_command
(
&
url
,
&
key
,
agent
)
?
;
}
}
}
}
Ok
(())
Ok
(())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论