From 73e76dca56ab3187bc9179975dfe9feb15a0c475 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 22 Feb 2016 18:45:17 +0100 Subject: [PATCH] files: make 'files ls' defaults to / License: MIT Signed-off-by: Christian Couder --- core/commands/files/files.go | 12 ++++++++++-- test/sharness/t0250-files-api.sh | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/commands/files/files.go b/core/commands/files/files.go index 9f10a8c54aa..5f2a7e01442 100644 --- a/core/commands/files/files.go +++ b/core/commands/files/files.go @@ -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 diff --git a/test/sharness/t0250-files-api.sh b/test/sharness/t0250-files-api.sh index 4544da473a5..25abd187345 100755 --- a/test/sharness/t0250-files-api.sh +++ b/test/sharness/t0250-files-api.sh @@ -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 '