files: make 'files ls' defaults to /

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
Christian Couder 2016-02-22 18:45:17 +01:00
parent 2600a0290a
commit 73e76dca56
2 changed files with 16 additions and 2 deletions

View File

@ -249,13 +249,21 @@ Examples:
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("path", true, false, "Path to show listing for."),
cmds.StringArg("path", false, false, "Path to show listing for. Defaults to '/'."),
},
Options: []cmds.Option{
cmds.BoolOption("l", "Use long listing format."),
},
Run: func(req cmds.Request, res cmds.Response) {
path, err := checkPath(req.Arguments()[0])
var arg string
if len(req.Arguments()) == 0 {
arg = "/"
} else {
arg = req.Arguments()[0]
}
path, err := checkPath(arg)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return

View File

@ -51,6 +51,12 @@ test_files_api() {
ipfs files mkdir /cats
'
test_expect_success "'files ls' lists root by default" '
ipfs files ls >actual &&
echo "cats" >expected &&
test_cmp expected actual
'
test_expect_success "directory was created" '
verify_path_exists /cats
'