From a50747a64acaa216c2242807ff9a883bee5934e7 Mon Sep 17 00:00:00 2001 From: Artem Chernyshev Date: Tue, 1 Mar 2022 13:21:13 +0300 Subject: [PATCH] fix: align list and diskusage command flags with their Linux analogs Fixes: https://github.com/talos-systems/talos/issues/3018 Signed-off-by: Artem Chernyshev --- cmd/talosctl/cmd/talos/diskusage.go | 2 +- cmd/talosctl/cmd/talos/list.go | 12 ++++++++++-- internal/integration/cli/diskusage.go | 2 +- internal/integration/cli/list.go | 17 +++-------------- website/content/docs/v0.15/Reference/cli.md | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/talosctl/cmd/talos/diskusage.go b/cmd/talosctl/cmd/talos/diskusage.go index 084e5c3d8..ab299f909 100644 --- a/cmd/talosctl/cmd/talos/diskusage.go +++ b/cmd/talosctl/cmd/talos/diskusage.go @@ -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, diff --git a/cmd/talosctl/cmd/talos/list.go b/cmd/talosctl/cmd/talos/list.go index 92691037e..4d1a3b923 100644 --- a/cmd/talosctl/cmd/talos/list.go +++ b/cmd/talosctl/cmd/talos/list.go @@ -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 := "/" @@ -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, }) @@ -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) } diff --git a/internal/integration/cli/diskusage.go b/internal/integration/cli/diskusage.go index f35ada7ce..e365cceca 100644 --- a/internal/integration/cli/diskusage.go +++ b/internal/integration/cli/diskusage.go @@ -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 { diff --git a/internal/integration/cli/list.go b/internal/integration/cli/list.go index 4917596dc..efa010b50 100644 --- a/internal/integration/cli/list.go +++ b/internal/integration/cli/list.go @@ -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: 1, flags: []string{"--depth=2"}}, + {separators: 2, 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: 5, flags: []string{"--recurse=true"}}, } { test := test suite.Run(strings.Join(test.flags, ","), func() { diff --git a/website/content/docs/v0.15/Reference/cli.md b/website/content/docs/v0.15/Reference/cli.md index b2d2ea16d..291ec83bd 100644 --- a/website/content/docs/v0.15/Reference/cli.md +++ b/website/content/docs/v0.15/Reference/cli.md @@ -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