Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
f039aa44
Commit
f039aa44
authored
Jul 08, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
533643e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
32 deletions
+29
-32
cli/parse.go
cli/parse.go
+6
-1
request.go
request.go
+23
-31
No files found.
cli/parse.go
View file @
f039aa44
...
...
@@ -17,6 +17,11 @@ import (
var
log
=
logging
.
Logger
(
"commands/cli"
)
// stdinSpecialName is a name applied to the 'stdin' file so we can differentiate
// it from potential 'real' files being passed in. The '*' character is invalid in
// path names and won't appear otherwise.
const
stdinSpecialName
=
"*stdin*"
// Parse parses the input commandline string (cmd, flags, and args).
// returns the corresponding command Request object.
func
Parse
(
input
[]
string
,
stdin
*
os
.
File
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
*
cmds
.
Command
,
[]
string
,
error
)
{
...
...
@@ -302,7 +307,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
return
nil
,
nil
,
err
}
if
istty
{
fname
=
"*
stdin
*"
fname
=
stdin
SpecialName
}
fileArgs
[
stdin
.
Name
()]
=
files
.
NewReaderFile
(
fname
,
""
,
stdin
,
nil
)
...
...
request.go
View file @
f039aa44
...
...
@@ -200,8 +200,8 @@ func (r *request) Context() context.Context {
}
func
(
r
*
request
)
haveVarArgsFromStdin
()
bool
{
// we expect varargs if we have a
variadic required argument and no arguments to
//
fill
it
// we expect varargs if we have a
string argument that supports stdin
//
and not arguments to satisfy
it
if
len
(
r
.
cmd
.
Arguments
)
==
0
{
return
false
}
...
...
@@ -214,16 +214,8 @@ func (r *request) haveVarArgsFromStdin() bool {
// VarArgs can be used when you want string arguments as input
// and also want to be able to handle them in a streaming fashion
func
(
r
*
request
)
VarArgs
(
f
func
(
string
)
error
)
error
{
var
i
int
for
i
=
0
;
i
<
len
(
r
.
cmd
.
Arguments
);
i
++
{
if
r
.
cmd
.
Arguments
[
i
]
.
Variadic
||
r
.
cmd
.
Arguments
[
i
]
.
SupportsStdin
{
break
}
}
args
:=
r
.
arguments
[
i
:
]
if
len
(
args
)
>
0
{
for
_
,
arg
:=
range
args
{
if
len
(
r
.
arguments
)
>=
len
(
r
.
cmd
.
Arguments
)
{
for
_
,
arg
:=
range
r
.
arguments
[
len
(
r
.
cmd
.
Arguments
)
-
1
:
]
{
err
:=
f
(
arg
)
if
err
!=
nil
{
return
err
...
...
@@ -231,29 +223,29 @@ func (r *request) VarArgs(f func(string) error) error {
}
return
nil
}
else
{
if
r
.
files
!=
nil
{
fi
,
err
:=
r
.
files
.
NextFile
()
if
err
!=
nil
{
return
err
}
}
if
fi
.
FileName
()
==
"*stdin*"
{
fmt
.
Fprintln
(
os
.
Stderr
,
"ipfs: Reading from stdin; send Ctrl-d to stop.
"
)
}
if
r
.
files
==
nil
{
return
fmt
.
Errorf
(
"expected more arguments from stdin
"
)
}
scan
:=
bufio
.
NewScanner
(
fi
)
for
scan
.
Scan
()
{
err
:=
f
(
scan
.
Text
())
if
err
!=
nil
{
return
err
}
}
return
nil
}
else
{
return
fmt
.
Errorf
(
"expected more arguments from stdin"
)
fi
,
err
:=
r
.
files
.
NextFile
()
if
err
!=
nil
{
return
err
}
if
fi
.
FileName
()
==
"*stdin*"
{
fmt
.
Fprintln
(
os
.
Stderr
,
"ipfs: Reading from stdin; send Ctrl-d to stop."
)
}
scan
:=
bufio
.
NewScanner
(
fi
)
for
scan
.
Scan
()
{
err
:=
f
(
scan
.
Text
())
if
err
!=
nil
{
return
err
}
}
return
nil
}
func
getContext
(
base
context
.
Context
,
req
Request
)
(
context
.
Context
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment