Skip to content

Conversation

@iTrooz
Copy link

@iTrooz iTrooz commented Nov 12, 2025

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers
under the terms of the Apache 2 license.
By creating this pull request I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 license.

Description & context

Add a --sort=size option to mcli ls to be able to sort files by size

Usually, you would do that by piping to sort, or using the --sort flag of ls

How to test this PR?

Compare go run . ls <path> and go run . ls <path> --sort=size

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Fixes a regression (If yes, please add commit-id or PR # here)
  • Unit tests added/updated
  • Internal documentation updated (??)
  • Create a documentation update request here

@iTrooz
Copy link
Author

iTrooz commented Nov 12, 2025

I'm waiting for initial feature approval before adding tests/making a PR to the docs repo

Copy link
Contributor

@klauspost klauspost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure it should be there. But leaving for others to decide.

@iTrooz
Copy link
Author

iTrooz commented Dec 4, 2025

@shtripat @harshavardhana Hello ! Would it be possible to review this PR please ? Thank you

@shtripat
Copy link
Contributor

shtripat commented Dec 4, 2025

I am confused about the value add of this feature. If we really need such a thing, we can use --json output and then sort as and when needed. Something like mc ls ALIAS/BUCKET -r --json | jq -s 'sort_by(.size) | .[] | {key, size}'

@iTrooz
Copy link
Author

iTrooz commented Dec 4, 2025

We could do that, but but the --json | jq -s 'sort_by(.size) | .[] | {key, size}' part is a bit cumbersome (I personally wouldn't be able to pull it off in a reasonable time), which is why I added the --sort. It is purely a QoL feature

@shtripat
Copy link
Contributor

shtripat commented Dec 4, 2025

We could do that, but but the --json | jq -s 'sort_by(.size) | .[] | {key, size}' part is a bit cumbersome (I personally wouldn't be able to pull it off in a reasonable time), which is why I added the --sort. It is purely a QoL feature

IIUC this kind of sorting is needed when we are programmatically processing the output and --json is meant to be used for this purpose. But lets hear from Harsha as well.

@iTrooz
Copy link
Author

iTrooz commented Dec 4, 2025

My use case was "I want to see what the biggest files are in this bucket" (not in the context of a script, purely me out of curiosity)
Maybe there is already a way to do that that I missed ?

But lets hear from Harsha as well.

Ok !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants