Skip to content

Commit a50747a

Browse files
committed
fix: align list and diskusage command flags with their Linux analogs
Fixes: #3018 Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
1 parent d29e920 commit a50747a

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

cmd/talosctl/cmd/talos/diskusage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var duCmd = &cobra.Command{
4141
}
4242

4343
stream, err := c.DiskUsage(ctx, &machineapi.DiskUsageRequest{
44-
RecursionDepth: recursionDepth,
44+
RecursionDepth: recursionDepth + 1,
4545
All: all,
4646
Threshold: threshold,
4747
Paths: paths,

cmd/talosctl/cmd/talos/list.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var lsCmd = &cobra.Command{
4646
return completePathFromNode(toComplete), cobra.ShellCompDirectiveNoFileComp
4747
},
4848
RunE: func(cmd *cobra.Command, args []string) error {
49+
if recurse && recursionDepth != 1 {
50+
return fmt.Errorf("only one of flags --recurse and --depth can be specified at the same time")
51+
}
52+
4953
return WithClient(func(ctx context.Context, c *client.Client) error {
5054
rootDir := "/"
5155

@@ -71,9 +75,13 @@ var lsCmd = &cobra.Command{
7175
}
7276
}
7377

78+
if recurse {
79+
recursionDepth = -1
80+
}
81+
7482
stream, err := c.LS(ctx, &machineapi.ListRequest{
7583
Root: rootDir,
76-
Recurse: recurse,
84+
Recurse: recursionDepth > 1 || recurse,
7785
RecursionDepth: recursionDepth,
7886
Types: reqTypes,
7987
})
@@ -211,7 +219,7 @@ func init() {
211219
lsCmd.Flags().BoolVarP(&long, "long", "l", false, "display additional file details")
212220
lsCmd.Flags().BoolVarP(&recurse, "recurse", "r", false, "recurse into subdirectories")
213221
lsCmd.Flags().BoolVarP(&humanizeFlag, "humanize", "H", false, "humanize size and time in the output")
214-
lsCmd.Flags().Int32VarP(&recursionDepth, "depth", "d", 0, "maximum recursion depth")
222+
lsCmd.Flags().Int32VarP(&recursionDepth, "depth", "d", 1, "maximum recursion depth")
215223
lsCmd.Flags().StringSliceVarP(&types, "type", "t", nil, typesHelp)
216224
addCommand(lsCmd)
217225
}

internal/integration/cli/diskusage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (suite *DiskUsageSuite) TestSuccess() {
9595
}))
9696

9797
// check total calculation
98-
suite.RunCLI([]string{"usage", "--nodes", node, folder, "-d2", "--all"},
98+
suite.RunCLI([]string{"usage", "--nodes", node, folder, "-d1", "--all"},
9999
base.StdoutMatchFunc(func(stdout string) error {
100100
lines := strings.Split(strings.TrimSpace(stdout), "\n")
101101
if len(lines) == 1 {

internal/integration/cli/list.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,14 @@ func (suite *ListSuite) TestDepth() {
8787
{separators: 0},
8888

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

9291
{separators: 0, flags: []string{"--depth=-1"}},
9392
{separators: 0, flags: []string{"--depth=0"}},
9493
{separators: 0, flags: []string{"--depth=1"}},
95-
{separators: 0, flags: []string{"--depth=2"}},
96-
{separators: 0, flags: []string{"--depth=3"}},
97-
98-
{separators: 0, flags: []string{"--recurse=false", "--depth=-1"}},
99-
{separators: 0, flags: []string{"--recurse=false", "--depth=0"}},
100-
{separators: 0, flags: []string{"--recurse=false", "--depth=1"}},
101-
{separators: 0, flags: []string{"--recurse=false", "--depth=2"}},
102-
{separators: 0, flags: []string{"--recurse=false", "--depth=3"}},
103-
104-
{separators: 5, flags: []string{"--recurse=true", "--depth=-1"}},
105-
{separators: 5, flags: []string{"--recurse=true", "--depth=0"}},
106-
{separators: 0, flags: []string{"--recurse=true", "--depth=1"}},
107-
{separators: 1, flags: []string{"--recurse=true", "--depth=2"}},
108-
{separators: 2, flags: []string{"--recurse=true", "--depth=3"}},
94+
{separators: 1, flags: []string{"--depth=2"}},
95+
{separators: 2, flags: []string{"--depth=3"}},
96+
97+
{separators: 5, flags: []string{"--recurse=true"}},
10998
} {
11099
test := test
111100
suite.Run(strings.Join(test.flags, ","), func() {

website/content/docs/v0.15/Reference/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ talosctl list [path] [flags]
14701470
### Options
14711471

14721472
```
1473-
-d, --depth int32 maximum recursion depth
1473+
-d, --depth int32 maximum recursion depth (default 1)
14741474
-h, --help help for list
14751475
-H, --humanize humanize size and time in the output
14761476
-l, --long display additional file details

0 commit comments

Comments
 (0)