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
c01c951a
Commit
c01c951a
authored
Nov 14, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Added a flag to enable stdin arguments
parent
4567e0f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
argument.go
argument.go
+11
-5
cli/parse.go
cli/parse.go
+2
-2
No files found.
argument.go
View file @
c01c951a
...
...
@@ -8,11 +8,12 @@ const (
)
type
Argument
struct
{
Name
string
Type
ArgumentType
Required
bool
Variadic
bool
Description
string
Name
string
Type
ArgumentType
Required
bool
Variadic
bool
SupportsStdin
bool
Description
string
}
func
StringArg
(
name
string
,
required
,
variadic
bool
,
description
string
)
Argument
{
...
...
@@ -34,3 +35,8 @@ func FileArg(name string, required, variadic bool, description string) Argument
Description
:
description
,
}
}
func
(
a
Argument
)
EnableStdin
()
Argument
{
a
.
SupportsStdin
=
true
return
a
}
cli/parse.go
View file @
c01c951a
...
...
@@ -171,7 +171,7 @@ func parseArgs(stringArgs []string, stdin *os.File, arguments []cmds.Argument) (
args
=
append
(
args
,
stringArgs
[
0
])
stringArgs
=
stringArgs
[
1
:
]
}
else
{
}
else
if
argDef
.
SupportsStdin
{
// if we have a stdin, read it in and use the data as a string value
var
buf
bytes
.
Buffer
_
,
err
:=
buf
.
ReadFrom
(
stdin
)
...
...
@@ -192,7 +192,7 @@ func parseArgs(stringArgs []string, stdin *os.File, arguments []cmds.Argument) (
args
=
append
(
args
,
file
)
stringArgs
=
stringArgs
[
1
:
]
}
else
{
}
else
if
argDef
.
SupportsStdin
{
// if we have a stdin, use that as a reader
args
=
append
(
args
,
stdin
)
stdin
=
nil
...
...
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