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.
@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.

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?

Copy link
Author

Choose a reason for hiding this comment

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

change has been made

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..

Copy link
Author

Choose a reason for hiding this comment

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

change has been made

@vexx32 vexx32 removed their assignment Sep 10, 2025
@swaran18999 swaran18999 force-pushed the list-command-with-date branch from 0b53340 to 7a04017 Compare September 23, 2025 00:58
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.
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.
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 force-pushed the list-command-with-date branch from 60dcb8a to 9537707 Compare September 23, 2025 01:08
@swaran18999 swaran18999 requested a review from vexx32 September 23, 2025 01:08
@vexx32
Copy link
Member

vexx32 commented Oct 30, 2025

Alright, I've given it a run through and I do have some comments/concerns with this current implementation. It looks like the Published date is not the correct thing to use here, primarily because it only looks at the file's LastModifiedTime as a UTC time. This isn't a sufficiently reliable metric for this purpose; there are cases where choco may modify the nupkg file, so this date isn't guaranteed to be the same as the date the package was actually installed or updated.

What we're going to need to do is a bit more involved if we want to do this. Probably the simplest approach is going to be taking notes from how the .deploymentLocation file works.

First, we have a static property that just stores the filename as a constant. You'll need to add another, call it .lastUpdated

private const string DeploymentLocationFile = ".deploymentLocation";

Second, it will need to have read/write logic in this file to save and load this data (the install/upgrade/etc methods in NugetService call into here, so you can just add logic into here in order to save/load this data), similar to this and around the same areas of the file:

var locationFile = _fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile);
if (_fileSystem.FileExists(locationFile))
{
FaultTolerance.TryCatchWithLoggingException(
() =>
{
packageInformation.DeploymentLocation = _fileSystem.ReadFile(locationFile);
},
"Unable to read deployment location file",
throwError: false,
logWarningInsteadOfError: true
);
}

_fileSystem.WriteFile(_fileSystem.CombinePaths(pkgStorePath, SilentUninstallerFile), string.Empty, Encoding.ASCII);
}
// Legacy side-by-side installation data cleanup
_fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, SideBySideFile));
if (packageInformation.IsPinned)
{
_fileSystem.WriteFile(_fileSystem.CombinePaths(pkgStorePath, PinFile), string.Empty, Encoding.ASCII);
}

When saving this information I think it would make the most sense to grab the value of DateTime.Now and just store that.

And then, once you have those two pieces in place, the current place you've added the logic to display it into will need to be amended. Specifically you'll need to copy what's done for deploymentLocation here and do similar to retrieve the last updated date:

https://github.com/chocolatey/choco/blob/97bc0d4b06864ec17788c892c7cbbdbf1f0befeb/src/chocolatey/infrastructure.app/services/NugetService.cs#L220C24-L241

This can then be displayed in the list output if needed.

@swaran18999 swaran18999 force-pushed the list-command-with-date branch from 6833723 to ee85b50 Compare November 4, 2025 04:10
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`.
Add support for reading and writing the .lastUpdated file for package
information to track when packages were last modified.

Add LastUpdated property to ChocolateyPackageInformation domain to
store the timestamp. Update ChocolateyPackageInformationService.Get
to read .lastUpdated files.

Modify ChocolateyPackageInformationService.Save to persist or remove
.lastUpdated files, fetching the current timestamp from NugetService
via DateTime.Now.
Add support for ordering packages by last updated date in the list
command, providing users with a new sorting option to view packages
by their most recent updates.
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