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 <artem.chernyshev@talos-systems.com>
This commit is contained in:
Artem Chernyshev 2022-03-01 13:21:13 +03:00
parent d29e9202f3
commit a50747a64a
No known key found for this signature in database
GPG Key ID: 9B9D0328B57B443F
5 changed files with 16 additions and 19 deletions

View File

@ -41,7 +41,7 @@ var duCmd = &cobra.Command{
} }
stream, err := c.DiskUsage(ctx, &machineapi.DiskUsageRequest{ stream, err := c.DiskUsage(ctx, &machineapi.DiskUsageRequest{
RecursionDepth: recursionDepth, RecursionDepth: recursionDepth + 1,
All: all, All: all,
Threshold: threshold, Threshold: threshold,
Paths: paths, Paths: paths,

View File

@ -46,6 +46,10 @@ var lsCmd = &cobra.Command{
return completePathFromNode(toComplete), cobra.ShellCompDirectiveNoFileComp return completePathFromNode(toComplete), cobra.ShellCompDirectiveNoFileComp
}, },
RunE: func(cmd *cobra.Command, args []string) error { 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 { return WithClient(func(ctx context.Context, c *client.Client) error {
rootDir := "/" rootDir := "/"
@ -71,9 +75,13 @@ var lsCmd = &cobra.Command{
} }
} }
if recurse {
recursionDepth = -1
}
stream, err := c.LS(ctx, &machineapi.ListRequest{ stream, err := c.LS(ctx, &machineapi.ListRequest{
Root: rootDir, Root: rootDir,
Recurse: recurse, Recurse: recursionDepth > 1 || recurse,
RecursionDepth: recursionDepth, RecursionDepth: recursionDepth,
Types: reqTypes, Types: reqTypes,
}) })
@ -211,7 +219,7 @@ func init() {
lsCmd.Flags().BoolVarP(&long, "long", "l", false, "display additional file details") lsCmd.Flags().BoolVarP(&long, "long", "l", false, "display additional file details")
lsCmd.Flags().BoolVarP(&recurse, "recurse", "r", false, "recurse into subdirectories") 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().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) lsCmd.Flags().StringSliceVarP(&types, "type", "t", nil, typesHelp)
addCommand(lsCmd) addCommand(lsCmd)
} }

View File

@ -95,7 +95,7 @@ func (suite *DiskUsageSuite) TestSuccess() {
})) }))
// check total calculation // 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 { base.StdoutMatchFunc(func(stdout string) error {
lines := strings.Split(strings.TrimSpace(stdout), "\n") lines := strings.Split(strings.TrimSpace(stdout), "\n")
if len(lines) == 1 { if len(lines) == 1 {

View File

@ -87,25 +87,14 @@ func (suite *ListSuite) TestDepth() {
{separators: 0}, {separators: 0},
{separators: 0, flags: []string{"--recurse=false"}}, {separators: 0, flags: []string{"--recurse=false"}},
{separators: 5, flags: []string{"--recurse=true"}},
{separators: 0, flags: []string{"--depth=-1"}}, {separators: 0, flags: []string{"--depth=-1"}},
{separators: 0, flags: []string{"--depth=0"}}, {separators: 0, flags: []string{"--depth=0"}},
{separators: 0, flags: []string{"--depth=1"}}, {separators: 0, flags: []string{"--depth=1"}},
{separators: 0, flags: []string{"--depth=2"}}, {separators: 1, flags: []string{"--depth=2"}},
{separators: 0, flags: []string{"--depth=3"}}, {separators: 2, flags: []string{"--depth=3"}},
{separators: 0, flags: []string{"--recurse=false", "--depth=-1"}}, {separators: 5, flags: []string{"--recurse=true"}},
{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"}},
} { } {
test := test test := test
suite.Run(strings.Join(test.flags, ","), func() { suite.Run(strings.Join(test.flags, ","), func() {

View File

@ -1470,7 +1470,7 @@ talosctl list [path] [flags]
### Options ### Options
``` ```
-d, --depth int32 maximum recursion depth -d, --depth int32 maximum recursion depth (default 1)
-h, --help help for list -h, --help help for list
-H, --humanize humanize size and time in the output -H, --humanize humanize size and time in the output
-l, --long display additional file details -l, --long display additional file details