Merge pull request #1492 from nak3/fs-update

Add validation of -n and -c options
This commit is contained in:
Alex Dadgar 2016-08-01 17:04:45 -07:00 committed by GitHub
commit b4a661ca7d
1 changed files with 7 additions and 4 deletions

View File

@ -56,8 +56,8 @@ FS Specific Options:
Show file stat information instead of displaying the file, or listing the directory.
-f
Causes the output to not stop when the end of the file is reached, but
rather to wait for additional output.
Causes the output to not stop when the end of the file is reached, but rather to
wait for additional output.
-tail
Show the files contents with offsets relative to the end of the file. If no
@ -68,7 +68,7 @@ FS Specific Options:
of the file.
-c
Sets the tail location in number of bytes relative to the end of the file.
Sets the tail location in number of bytes relative to the end of the file.
`
return strings.TrimSpace(helpText)
}
@ -262,7 +262,10 @@ func (f *FSCommand) Run(args []string) int {
var offset int64 = defaultTailLines * bytesToLines
if nLines, nBytes := numLines != -1, numBytes != -1; nLines && nBytes {
f.Ui.Error("Both -n and -c set")
f.Ui.Error("Both -n and -c are not allowed")
return 1
} else if numLines < -1 || numBytes < -1 {
f.Ui.Error("Invalid size is specified")
return 1
} else if nLines {
offset = numLines * bytesToLines