aspnet / LibraryManager

Other
446 stars 78 forks source link

Add a --whatif option to CLI update command #732

Closed jimmylewis closed 2 months ago

jimmylewis commented 3 months ago

This flag will cause the command to print a message indicating what changes would be made, but not commit any changes to the file system. It's useful to plan in advance before making changes.

Resolves #723

phil-allen-msft commented 2 months ago

Do you have a matching example where 'whatif' shows only a small amount of output? I think I've seen other tools that will (with different command names, like 'dry run') give near identical output to the command if run without the option, albeit not actually making any changes.

jimmylewis commented 2 months ago

Here's a comparison:

PS C:\temp\project> libman update jquery --whatif
Library "jquery" would be updated to latest version "3.7.1"
PS C:\temp\project> libman update jquery
Restoring library jquery@3.7.1...
lib/jquery/jquery.js written to disk
lib/jquery/jquery.min.js written to disk
lib/jquery/jquery.min.map written to disk
lib/jquery/jquery.slim.js written to disk
lib/jquery/jquery.slim.min.js written to disk
lib/jquery/jquery.slim.min.map written to disk
Updated "jquery" to "3.7.1"

--whatif does not say each file that would be written to disk, but that's based on the rest of the library entry (namely the "files" property, not the "library" property). Given a that some libraries have hundreds of files, the succinct output is the most relevant - which version of the library will it be updated to. I'd rather not show the full output of doing the restore. (This example also doesn't include downloading the library for the first time since I already had it cached, so it would be ~2x as much output.)

phil-allen-msft commented 2 months ago

Different question, do you have a non-libman command that has --what-if to show an analogous behavior?

jimmylewis commented 2 months ago

Many PowerShell cmdlets use the -WhatIf convention (provided in PS via CmdletBinding), as does the Azure CLI (non-PS), and I'm sure I've seen it elsewhere before. PS example:

PS D:\src> Remove-Item -Recurse c:\windows\system32 -WhatIf
What if: Performing the operation "Remove Directory" on target "C:\windows\system32".

Some other tools use --dry-run such as git and npm:

PS D:\temp> npm install --dry-run bootstrap

added 2 packages in 398ms

but I find that output less clear that it didn't do anything, or what it would do.