Skip to content

Conversation

swaran18999
Copy link

@swaran18999 swaran18999 commented Aug 23, 2025

Description Of Changes

  • Add --show-last-updated-date option to choco list to display the last date a package was installed/updated, formatted as yyyy-MM-dd HH:mm:ss. Falls back to “Last updated not available” when metadata is missing.
  • Add --order-by-last-updated-date option to choco list to order results by the package’s last installed/updated date by mapping to PackageOrder.LastPublished.
  • Update PowerShell tab completion (src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1) to include both new switches in the list command’s completion options.

Motivation and Context

  • Administrators and users often need quick visibility into when packages were last installed or updated, and to sort lists by recency for auditing and maintenance workflows. Previously, choco list did not expose this information nor allow sorting by it.
  • These additions improve usability by displaying last-change timestamps inline with list results.
  • This work addresses the needs discussed in issue Improving choco list with options to show dependencies and sort by date (and more) #1276

Testing

  • Flag parsing for --show-last-updated-date sets ShowLastUpdatedDate = true; defaults to false when omitted. Output includes formatted date yyyy-MM-dd HH:mm:ss when Published exists.
  • Sorting places packages in the expected order by last updated date.
  • Correct order when --order-by-last-updated-date is used.
  • Behavior is consistent with --id-only/--by-id-only (date not appended, sorting still applied).

Operating Systems Testing

  • Windows 10

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

Partially fixes #1276

Add `--show-last-updated-date` option to the `list` command. When
enabled, this displays the last date the package was installed or
updated, alongside the usual metadata fields.

Previously, users had no clear indication of when a local package was
last changed. This new option provides better visibility and helps
with package management, especially when filtering or sorting package
lists by recency.

Implementation details:
- Introduced new switch `show-last-updated-date`.
- Logs formatted date via `package.Published` (or fallback string if
  unavailable).
- Integrated into existing `list` command output formatting.

With this change, users can more easily audit their package states
and track updates over time.
Add `--order-by-last-updated-date` option to the `list` command. When
used, the command output is ordered by the date each package was last
installed or updated.

Previously, package listings were only ordered by name or version.
This limited users who wanted to quickly identify the most recently
changed packages. With this new option, users gain more control over
list output and can better manage their environments based on package
activity.

Implementation details:
- Introduced new switch `order-by-last-updated-date`.
- Maps user input to `PackageOrder.LastPublished`.
- Integrates naturally into existing sort logic of `list`.
Update `ChocolateyTabExpansion.ps1` to include the new
`--show-last-updated-date` and `--order-by-last-updated-date` switches
in the `list` command's tab completion options.
@swaran18999 swaran18999 changed the title List command with date List command with last updated date Aug 23, 2025
@swaran18999 swaran18999 changed the title List command with last updated date (#1276) List command with last updated date Aug 29, 2025
@vexx32 vexx32 self-assigned this Sep 10, 2025
Copy link
Member

@vexx32 vexx32 left a comment

Choose a reason for hiding this comment

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

Looks pretty solid, nice self-contained change, just a couple minor comments.

You will need to rebase this branch against develop when you're done, just so the merge history is a bit tidier.

@@ -49,7 +49,7 @@ $commandOptions = @{
info = "--cert='' --certpassword='' --disable-repository-optimizations --include-configured-sources --local-only --password='' --prerelease --source='' --user='' --version=''"
install = "--allow-downgrade --allow-empty-checksums --allow-empty-checksums-secure --apply-args-to-dependencies --apply-package-parameters-to-dependencies --cert='' --certpassword='' --disable-repository-optimizations --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --download-checksum-type-x64='' --exit-when-reboot-detected --force-dependencies --forcex86 --ignore-checksum --ignore-dependencies --ignore-detected-reboot --ignore-package-exit-codes --include-configured-sources --install-arguments='' --not-silent --override-arguments --package-parameters='' --password='' --pin --prerelease --require-checksums --skip-hooks --skip-scripts --source='' --stop-on-first-failure --use-package-exit-codes --user='' --version=''"
license = ""
list = "--by-id-only --by-tag-only --detail --exact --id-only --id-starts-with --ignore-pinned --include-programs --page='' --page-size='' --prerelease --source='' --version=''"
list = "--by-id-only --by-tag-only --detail --exact --id-only --id-starts-with --ignore-pinned --include-programs --page='' --page-size='' --prerelease --order-by-last-updated-date --show-last-updated-date --source='' --version=''"
Copy link
Member

Choose a reason for hiding this comment

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

I think most of our flags are given in alphabetical order in tab completion; could we put these in before --page?

@@ -276,11 +276,12 @@ it is possible that incomplete package lists are returned from a command
{
if (!(packageInfo != null && packageInfo.IsPinned && config.ListCommand.IgnorePinned))
{
this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}".FormatWith(
this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3} {4}".FormatWith(
Copy link
Member

Choose a reason for hiding this comment

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

Looking at how the other information is added here, it looks like the space before each arg is added below rather than here; I'm guessing that's probably due to not wanting to add trailing space and also to keep it simple to extend later on. For consistency's sake, can we do the same here? i.e., no space in this format string, but adding the space if the user is asking to show the last updated date -- similar to how the Approved / download cache information is done.

I think you can do that just by adding a space to the ToString() format string on line 284 and the "Last updated not available" string..

@vexx32 vexx32 removed their assignment Sep 10, 2025
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.

Improving choco list with options to show dependencies and sort by date (and more)
2 participants