Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
62fcf7e9
提交
62fcf7e9
authored
10月 17, 2016
作者:
Jeromy Johnson
提交者:
GitHub
10月 17, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3308 from ipfs/kevina/cli-refactor
cli: refactor to expose argument parsing functionality
上级
9cb6ac17
8570a529
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
22 行删除
+31
-22
cmd_suggestion.go
commands/cli/cmd_suggestion.go
+4
-0
parse.go
commands/cli/parse.go
+27
-22
没有找到文件。
commands/cli/cmd_suggestion.go
浏览文件 @
62fcf7e9
...
...
@@ -30,6 +30,10 @@ func (s suggestionSlice) Less(i, j int) bool {
}
func
suggestUnknownCmd
(
args
[]
string
,
root
*
cmds
.
Command
)
[]
string
{
if
root
==
nil
{
return
nil
}
arg
:=
args
[
0
]
var
suggestions
[]
string
sortableSuggestions
:=
make
(
suggestionSlice
,
0
)
...
...
commands/cli/parse.go
浏览文件 @
62fcf7e9
...
...
@@ -36,27 +36,6 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
return
nil
,
cmd
,
path
,
err
}
// if -r is provided, and it is associated with the package builtin
// recursive path option, allow recursive file paths
recursiveOpt
:=
req
.
Option
(
cmds
.
RecShort
)
recursive
:=
false
if
recursiveOpt
!=
nil
&&
recursiveOpt
.
Definition
()
==
cmds
.
OptionRecursivePath
{
recursive
,
_
,
err
=
recursiveOpt
.
Bool
()
if
err
!=
nil
{
return
req
,
nil
,
nil
,
u
.
ErrCast
()
}
}
// if '--hidden' is provided, enumerate hidden paths
hiddenOpt
:=
req
.
Option
(
"hidden"
)
hidden
:=
false
if
hiddenOpt
!=
nil
{
hidden
,
_
,
err
=
hiddenOpt
.
Bool
()
if
err
!=
nil
{
return
req
,
nil
,
nil
,
u
.
ErrCast
()
}
}
// This is an ugly hack to maintain our current CLI interface while fixing
// other stdin usage bugs. Let this serve as a warning, be careful about the
// choices you make, they will haunt you forever.
...
...
@@ -67,7 +46,7 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
}
}
stringArgs
,
fileArgs
,
err
:=
parseArgs
(
stringVals
,
stdin
,
cmd
.
Arguments
,
recursive
,
hidden
,
root
)
stringArgs
,
fileArgs
,
err
:=
ParseArgs
(
req
,
stringVals
,
stdin
,
cmd
.
Arguments
,
root
)
if
err
!=
nil
{
return
req
,
cmd
,
path
,
err
}
...
...
@@ -86,6 +65,32 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
return
req
,
cmd
,
path
,
nil
}
func
ParseArgs
(
req
cmds
.
Request
,
inputs
[]
string
,
stdin
*
os
.
File
,
argDefs
[]
cmds
.
Argument
,
root
*
cmds
.
Command
)
([]
string
,
[]
files
.
File
,
error
)
{
var
err
error
// if -r is provided, and it is associated with the package builtin
// recursive path option, allow recursive file paths
recursiveOpt
:=
req
.
Option
(
cmds
.
RecShort
)
recursive
:=
false
if
recursiveOpt
!=
nil
&&
recursiveOpt
.
Definition
()
==
cmds
.
OptionRecursivePath
{
recursive
,
_
,
err
=
recursiveOpt
.
Bool
()
if
err
!=
nil
{
return
nil
,
nil
,
u
.
ErrCast
()
}
}
// if '--hidden' is provided, enumerate hidden paths
hiddenOpt
:=
req
.
Option
(
"hidden"
)
hidden
:=
false
if
hiddenOpt
!=
nil
{
hidden
,
_
,
err
=
hiddenOpt
.
Bool
()
if
err
!=
nil
{
return
nil
,
nil
,
u
.
ErrCast
()
}
}
return
parseArgs
(
inputs
,
stdin
,
argDefs
,
recursive
,
hidden
,
root
)
}
// Parse a command line made up of sub-commands, short arguments, long arguments and positional arguments
func
parseOpts
(
args
[]
string
,
root
*
cmds
.
Command
)
(
path
[]
string
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论