@cryptotaxi247 / kubo / commits / 73e76dca5

files: make 'files ls' defaults to /

License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Feb 22, 2016 at 18:45 UTC 73e76dca56ab3187bc9179975dfe9feb15a0c475
2 files changed +16 -2
core/commands/files/files.go
+10 -2
@@ -249,13 +249,21 @@ Examples:
249 `,
250 },
251 Arguments: []cmds.Argument{
252 - cmds.StringArg("path", true, false, "Path to show listing for."),
252 + cmds.StringArg("path", false, false, "Path to show listing for. Defaults to '/'."),
253 },
254 Options: []cmds.Option{
255 cmds.BoolOption("l", "Use long listing format."),
256 },
257 Run: func(req cmds.Request, res cmds.Response) {
258 - path, err := checkPath(req.Arguments()[0])
258 + var arg string
259 +
260 + if len(req.Arguments()) == 0 {
261 + arg = "/"
262 + } else {
263 + arg = req.Arguments()[0]
264 + }
265 +
266 + path, err := checkPath(arg)
267 if err != nil {
268 res.SetError(err, cmds.ErrNormal)
269 return
test/sharness/t0250-files-api.sh
+6
@@ -51,6 +51,12 @@ test_files_api() {
51 ipfs files mkdir /cats
52 '
53
54 + test_expect_success "'files ls' lists root by default" '
55 + ipfs files ls >actual &&
56 + echo "cats" >expected &&
57 + test_cmp expected actual
58 + '
59 +
60 test_expect_success "directory was created" '
61 verify_path_exists /cats
62 '