Add --delete-source option and interactive prompt to project convert#52802
Add --delete-source option and interactive prompt to project convert#52802Copilot wants to merge 10 commits intorelease/10.0.3xxfrom
Conversation
…command Co-authored-by: jjonescz <[email protected]>
Co-authored-by: jjonescz <[email protected]>
… improve test assertions Co-authored-by: jjonescz <[email protected]>
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs
Show resolved
Hide resolved
test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs
Show resolved
Hide resolved
…ts, migrate to Spectre.Console, add tests with default files Co-authored-by: jjonescz <[email protected]>
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
…ory validation Co-authored-by: jjonescz <[email protected]>
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
…directory prompt Co-authored-by: jjonescz <[email protected]>
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
…nsole Co-authored-by: jjonescz <[email protected]>
|
@333fred @RikkiGibson for reviews, thanks |
|
Will try to take a look tomorrow. |
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| // Handle deletion of source file if requested. | ||
| bool shouldDelete = _deleteSource || TryAskForDeleteSource(file); |
There was a problem hiding this comment.
It feels confusing/limiting that, to prevent an interactive behavior, the user must specify to delete the source file. They can't specify to keep the source file in a scripting scenario.
Perhaps the command should accept something like --delete-source=false in addition to --delete-source. I'm not 100% up to speed on the best practices for CLI arguments like these.
There was a problem hiding this comment.
The System.CommandLine framework used in this codebase doesn't support --flag=false syntax for boolean options with ArgumentArity.Zero (confirmed by testing and examining all other boolean options in the codebase). All boolean flags in the SDK follow this pattern - they're either present (true) or absent (false).
For scripting scenarios where users want to explicitly prevent interactive prompts:
- Use
--interactive=falseis not supported - Instead, simply omit the
--interactiveflag (default is non-interactive) - The default behavior (no
--delete-source, no--interactive) already keeps the source file without prompting
This matches the convention used throughout the .NET CLI for all boolean flags.
There was a problem hiding this comment.
Instead, simply omit the --interactive flag (default is non-interactive)
it’s not clear to me that this is true. The command line help doesn’t report this, and, it’s not obvious that this would be the case in a script running on a local user machine.
There was a problem hiding this comment.
Yes, Rikki is right, the default for --interactive is different in CI and elsewhere, see this in CommonOptions.cs:
DefaultValueFactory = (ar) => !IsCIEnvironmentOrRedirected(),But it looks like we can create an interactive option that accepts an argument - could we perhaps use that version of the interactive option in the project convert command?
There was a problem hiding this comment.
Done in commit 5b38917. Changed InteractiveOption to use CreateInteractiveOption(acceptArgument: true) which allows --interactive=false in scripting scenarios.
The --interactive option now accepts a boolean argument (ArgumentArity.ZeroOrOne), so users can explicitly specify:
--interactiveor--interactive=trueto force interactive mode--interactive=falseto explicitly disable interactive prompts in scripts- No flag: defaults based on CI detection (true on local machines, false in CI/redirected output)
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: jjonescz <[email protected]>
Co-authored-by: jjonescz <[email protected]>
dotnet project convertcopies the source file to the new project directory but leaves the original file. Users expect "convert" to move the file, not duplicate it.Changes
--delete-sourceflag: Explicitly deletes source file after successful conversion--interactiveis enabled without--delete-source, prompts user via Spectre.Console selection to choose whether to delete the source file--dry-run --delete-source--interactive=falseexplicitly disables all prompts for reliable scriptingBehavior
Implementation Notes
--delete-sourceis used; other default files (e.g.,appsettings.json,Util.cs) are preserved--interactiveoption now accepts boolean arguments (--interactive=true/false) for explicit control in scriptsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.