Skip to content

Commit

Permalink
fix default flag behaviour in du command (#3031)
Browse files Browse the repository at this point in the history
- `mc du` without args should print help like other `mc` commands
- `mc du` should behave like `du -h --max-depth=1` as default
- optional `--recursive` if they want capacity for each folder.
fixes #2871
  • Loading branch information
balamurugana authored and kannappanr committed Jan 4, 2020
1 parent 6d1a414 commit 5076686
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/du-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ var (
Name: "depth, d",
Usage: "print the total for a folder prefix only if it is N or fewer levels below the command line argument",
},
cli.BoolFlag{
Name: "recursive, r",
Usage: "recursively print the total for a folder prefix",
},
}
)

Expand Down Expand Up @@ -153,6 +157,10 @@ func du(urlStr string, depth int, encKeyDB map[string][]prefixSSEPair) (int64, e

// main for du command.
func mainDu(ctx *cli.Context) error {
if !ctx.Args().Present() {
cli.ShowCommandHelpAndExit(ctx, "du", 1)
}

console.SetColor("Prefix", color.New(color.FgCyan, color.Bold))
console.SetColor("Size", color.New(color.FgYellow))

Expand All @@ -163,7 +171,13 @@ func mainDu(ctx *cli.Context) error {
// du specific flags.
depth := ctx.Int("depth")
if depth == 0 {
depth = -1
if ctx.Bool("recursive") {
if !ctx.IsSet("depth") {
depth = -1
}
} else {
depth = 1
}
}

// Set color.
Expand Down

0 comments on commit 5076686

Please sign in to comment.