Skip to content

Commit 5569ddb

Browse files
authored
Merge pull request #27 from microsoft/alzollin/certCommandFixes
Small fixes for cert command handling.
2 parents 9d76221 + 9130177 commit 5569ddb

File tree

11 files changed

+37
-43
lines changed

11 files changed

+37
-43
lines changed

src/winsdk-CLI/Winsdk.Cli/Commands/CertGenerateCommand.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ internal class CertGenerateCommand : Command
1212
public static Option<string> PasswordOption { get; }
1313
public static Option<int> ValidDaysOption { get; }
1414
public static Option<bool> InstallOption { get; }
15+
public static Option<IfExists> IfExistsOption { get; }
16+
17+
internal enum IfExists
18+
{
19+
Error,
20+
Overwrite,
21+
Skip
22+
}
1523

1624
static CertGenerateCommand()
1725
{
@@ -45,6 +53,11 @@ static CertGenerateCommand()
4553
Description = "Install the certificate to the local machine store after generation",
4654
DefaultValueFactory = (argumentResult) => false,
4755
};
56+
IfExistsOption = new Option<IfExists> ("--if-exists")
57+
{
58+
Description = "Skip generation if the certificate file already exists",
59+
DefaultValueFactory = (argumentResult) => IfExists.Error,
60+
};
4861
}
4962

5063
public CertGenerateCommand()
@@ -56,7 +69,7 @@ public CertGenerateCommand()
5669
Options.Add(PasswordOption);
5770
Options.Add(ValidDaysOption);
5871
Options.Add(InstallOption);
59-
Options.Add(WinSdkRootCommand.VerboseOption);
72+
Options.Add(IfExistsOption);
6073
}
6174

6275
public class Handler(ICertificateService certificateService) : AsynchronousCommandLineAction
@@ -69,14 +82,26 @@ public override async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio
6982
var password = parseResult.GetRequiredValue(PasswordOption);
7083
var validDays = parseResult.GetRequiredValue(ValidDaysOption);
7184
var install = parseResult.GetRequiredValue(InstallOption);
85+
var ifExists = parseResult.GetRequiredValue(IfExistsOption);
7286
var verbose = parseResult.GetValue(WinSdkRootCommand.VerboseOption);
7387

7488
// Check if certificate file already exists
7589
if (File.Exists(output))
7690
{
7791
Console.Error.WriteLine($"❌ Certificate file already exists: {output}");
78-
Console.Error.WriteLine("Please specify a different output path or remove the existing file.");
79-
return 1;
92+
if (ifExists == IfExists.Error)
93+
{
94+
Console.Error.WriteLine("Please specify a different output path or remove the existing file.");
95+
return 1;
96+
}
97+
else if (ifExists == IfExists.Skip)
98+
{
99+
return 0;
100+
}
101+
else if (ifExists == IfExists.Overwrite)
102+
{
103+
Console.WriteLine($"⚠️ Overwriting existing certificate file: {output}");
104+
}
80105
}
81106

82107
// Use the consolidated certificate generation method with all console output and error handling
@@ -86,7 +111,7 @@ await certificateService.GenerateDevCertificateWithInferenceAsync(
86111
manifestPath: manifestPath,
87112
password: password,
88113
validDays: validDays,
89-
skipIfExists: false, // We already checked above
114+
skipIfExists: false,
90115
updateGitignore: true,
91116
install: install,
92117
quiet: false,

src/winsdk-CLI/Winsdk.Cli/Commands/CertInstallCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public CertInstallCommand()
3434
Arguments.Add(CertPathArgument);
3535
Options.Add(PasswordOption);
3636
Options.Add(ForceOption);
37-
Options.Add(WinSdkRootCommand.VerboseOption);
3837
}
3938

4039
public class Handler(ICertificateService certificateService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/CreateDebugIdentityCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static CreateDebugIdentityCommand()
3838
Options.Add(ManifestOption);
3939
Options.Add(NoInstallOption);
4040
Options.Add(LocationOption);
41-
Options.Add(WinSdkRootCommand.VerboseOption);
4241
}
4342

4443
public class Handler(IMsixService msixService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/GetWinsdkPathCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ static GetWinsdkPathCommand()
1919
public GetWinsdkPathCommand() : base("get-winsdk-path", "Get the path to the .winsdk directory (local by default, global with --global)")
2020
{
2121
Options.Add(GlobalOption);
22-
Options.Add(WinSdkRootCommand.VerboseOption);
2322
}
2423

2524
public class Handler(IWinsdkDirectoryService winsdkDirectoryService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/InitCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ static InitCommand()
6969
Options.Add(YesOption);
7070
Options.Add(NoCertOption);
7171
Options.Add(ConfigOnlyOption);
72-
Options.Add(WinSdkRootCommand.VerboseOption);
7372
}
7473

7574
public class Handler(IWorkspaceSetupService workspaceSetupService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/ManifestGenerateCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public ManifestGenerateCommand() : base("generate", "Generate a manifest in dire
7979
Options.Add(SparseOption);
8080
Options.Add(LogoPathOption);
8181
Options.Add(YesOption);
82-
Options.Add(WinSdkRootCommand.VerboseOption);
8382
}
8483

8584
public class Handler(IManifestService manifestService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/PackageCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public PackageCommand()
8383
Options.Add(PublisherOption);
8484
Options.Add(ManifestOption);
8585
Options.Add(SelfContainedOption);
86-
Options.Add(WinSdkRootCommand.VerboseOption);
8786
}
8887

8988
public class Handler(IMsixService msixService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/RestoreCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public RestoreCommand() : base("restore", "Restore packages from winsdk.yaml and
3535
Arguments.Add(BaseDirectoryArgument);
3636
Options.Add(ConfigDirOption);
3737
Options.Add(QuietOption);
38-
Options.Add(WinSdkRootCommand.VerboseOption);
3938
}
4039

4140
public class Handler(IWorkspaceSetupService workspaceSetupService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/SignCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public SignCommand() : base("sign", "Sign a file/package with a certificate")
3838
Arguments.Add(CertPathArgument);
3939
Options.Add(PasswordOption);
4040
Options.Add(TimestampOption);
41-
Options.Add(WinSdkRootCommand.VerboseOption);
4241
}
4342

4443
public class Handler(ICertificateService certificateService) : AsynchronousCommandLineAction

src/winsdk-CLI/Winsdk.Cli/Commands/UpdateCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ static UpdateCommand()
2121
public UpdateCommand() : base("update", "Update packages in winsdk.yaml and install/update build tools in cache")
2222
{
2323
Options.Add(PrereleaseOption);
24-
Options.Add(WinSdkRootCommand.VerboseOption);
2524
}
2625

2726
public class Handler(

0 commit comments

Comments
 (0)