Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Test Developertest
提交
474c79e7
T
Test Developertest
项目概览
OpenHarmony
/
Test Developertest
大约 1 年 前同步成功
通知
2
Star
23
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Test Developertest
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
474c79e7
编写于
6月 24, 2022
作者:
L
leiqian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add logic to execute a command
Signed-off-by:
N
leiqian
<
leiqian@kaihongdigi.com
>
上级
3e0a408c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
0 deletion
+10
-0
src/core/command/console.py
src/core/command/console.py
+10
-0
未找到文件。
src/core/command/console.py
浏览文件 @
474c79e7
...
...
@@ -85,6 +85,7 @@ class Console(object):
else
:
self
.
command_parser
(
" "
.
join
(
args
[
1
:]))
# 命令执行总入口
def
_console
(
self
):
if
platform
.
system
()
!=
'Windows'
:
signal
.
signal
(
signal
.
SIGTSTP
,
self
.
handler_ctrl_z
)
# ctrl+x linux
...
...
@@ -92,9 +93,11 @@ class Console(object):
while
True
:
try
:
# 获取用户命令输入
usr_input
=
input
(
">>> "
)
if
usr_input
==
""
:
continue
# 用户输入命令解析
self
.
command_parser
(
usr_input
)
except
SystemExit
:
LOG
.
info
(
"Program exit normally!"
)
...
...
@@ -102,6 +105,7 @@ class Console(object):
except
(
IOError
,
EOFError
,
KeyboardInterrupt
)
as
error
:
LOG
.
exception
(
"Input Error: %s"
%
error
)
# 参数解析方法
@
classmethod
def
argument_parser
(
cls
,
para_list
):
"""
...
...
@@ -113,6 +117,8 @@ class Console(object):
parser
=
None
try
:
# argparse是一个Python模块:命令行选项、参数和子命令解析器
# 使用argparse的第一步:创建一个ArgumentParser对象,ArgumentParser对象包含将命令行解析成Python数据类型所需的全部信息
parser
=
argparse
.
ArgumentParser
(
description
=
"Specify test para."
)
parser
.
add_argument
(
"action"
,
type
=
str
.
lower
,
help
=
"Specify action"
)
...
...
@@ -208,6 +214,7 @@ class Console(object):
default
=
""
,
help
=
"Specify fuzzer name"
)
# 解析部分命令行参数,会返回一个由两个条目构成的元组,其中包含带成员的命名空间(options)和剩余参数字符串的列表(unparsed)
(
options
,
unparsed
)
=
parser
.
parse_known_args
(
para_list
)
# Set default value
...
...
@@ -228,12 +235,14 @@ class Console(object):
def
command_parser
(
self
,
args
):
try
:
# 将用户输入的指令按空格拆分成字符串数组
para_list
=
args
.
split
()
options
,
_
,
valid_param
=
self
.
argument_parser
(
para_list
)
if
options
is
None
or
not
valid_param
:
LOG
.
warning
(
"options is None."
)
return
# 根据命令行的命令选择不同的方法执行
command
=
options
.
action
if
command
==
""
:
LOG
.
warning
(
"action is empty."
)
...
...
@@ -288,6 +297,7 @@ class Console(object):
LOG
.
error
(
"Wrong gen command."
)
return
# run命令执行入口
@
classmethod
def
_process_command_run
(
cls
,
command
,
options
):
if
command
==
ToolCommandType
.
TOOLCMD_KEY_RUN
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录