Skip to content

Commit

Permalink
fix: align list and diskusage command flags with their Linux analogs
Browse files Browse the repository at this point in the history
Fixes: #3018

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever committed Mar 2, 2022
1 parent d29e920 commit a50747a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/diskusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var duCmd = &cobra.Command{
}

stream, err := c.DiskUsage(ctx, &machineapi.DiskUsageRequest{
RecursionDepth: recursionDepth,
RecursionDepth: recursionDepth + 1,
All: all,
Threshold: threshold,
Paths: paths,
Expand Down
12 changes: 10 additions & 2 deletions cmd/talosctl/cmd/talos/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var lsCmd = &cobra.Command{
return completePathFromNode(toComplete), cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
if recurse && recursionDepth != 1 {
return fmt.Errorf("only one of flags --recurse and --depth can be specified at the same time")
}

return WithClient(func(ctx context.Context, c *client.Client) error {
rootDir := "/"

Expand All @@ -71,9 +75,13 @@ var lsCmd = &cobra.Command{
}
}

if recurse {
recursionDepth = -1
}

stream, err := c.LS(ctx, &machineapi.ListRequest{
Root: rootDir,
Recurse: recurse,
Recurse: recursionDepth > 1 || recurse,
RecursionDepth: recursionDepth,
Types: reqTypes,
})
Expand Down Expand Up @@ -211,7 +219,7 @@ func init() {
lsCmd.Flags().BoolVarP(&long, "long", "l", false, "display additional file details")
lsCmd.Flags().BoolVarP(&recurse, "recurse", "r", false, "recurse into subdirectories")
lsCmd.Flags().BoolVarP(&humanizeFlag, "humanize", "H", false, "humanize size and time in the output")
lsCmd.Flags().Int32VarP(&recursionDepth, "depth", "d", 0, "maximum recursion depth")
lsCmd.Flags().Int32VarP(&recursionDepth, "depth", "d", 1, "maximum recursion depth")
lsCmd.Flags().StringSliceVarP(&types, "type", "t", nil, typesHelp)
addCommand(lsCmd)
}
2 changes: 1 addition & 1 deletion internal/integration/cli/diskusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (suite *DiskUsageSuite) TestSuccess() {
}))

// check total calculation
suite.RunCLI([]string{"usage", "--nodes", node, folder, "-d2", "--all"},
suite.RunCLI([]string{"usage", "--nodes", node, folder, "-d1", "--all"},
base.StdoutMatchFunc(func(stdout string) error {
lines := strings.Split(strings.TrimSpace(stdout), "\n")
if len(lines) == 1 {
Expand Down
19 changes: 4 additions & 15 deletions internal/integration/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,14 @@ func (suite *ListSuite) TestDepth() {
{separators: 0},

{separators: 0, flags: []string{"--recurse=false"}},
{separators: 5, flags: []string{"--recurse=true"}},

{separators: 0, flags: []string{"--depth=-1"}},
{separators: 0, flags: []string{"--depth=0"}},
{separators: 0, flags: []string{"--depth=1"}},
{separators: 0, flags: []string{"--depth=2"}},
{separators: 0, flags: []string{"--depth=3"}},

{separators: 0, flags: []string{"--recurse=false", "--depth=-1"}},
{separators: 0, flags: []string{"--recurse=false", "--depth=0"}},
{separators: 0, flags: []string{"--recurse=false", "--depth=1"}},
{separators: 0, flags: []string{"--recurse=false", "--depth=2"}},
{separators: 0, flags: []string{"--recurse=false", "--depth=3"}},

{separators: 5, flags: []string{"--recurse=true", "--depth=-1"}},
{separators: 5, flags: []string{"--recurse=true", "--depth=0"}},
{separators: 0, flags: []string{"--recurse=true", "--depth=1"}},
{separators: 1, flags: []string{"--recurse=true", "--depth=2"}},
{separators: 2, flags: []string{"--recurse=true", "--depth=3"}},
{separators: 1, flags: []string{"--depth=2"}},
{separators: 2, flags: []string{"--depth=3"}},

{separators: 5, flags: []string{"--recurse=true"}},
} {
test := test
suite.Run(strings.Join(test.flags, ","), func() {
Expand Down
2 changes: 1 addition & 1 deletion website/content/docs/v0.15/Reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ talosctl list [path] [flags]
### Options

```
-d, --depth int32 maximum recursion depth
-d, --depth int32 maximum recursion depth (default 1)
-h, --help help for list
-H, --humanize humanize size and time in the output
-l, --long display additional file details
Expand Down

0 comments on commit a50747a

Please sign in to comment.