Skip to content

Commit 55d74ba

Browse files
committed
Write documentation of EasySign.CommandLine classes
1 parent 7eb300c commit 55d74ba

File tree

3 files changed

+96
-18
lines changed

3 files changed

+96
-18
lines changed

src/EasySign.CommandLine/BundleWorker.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ namespace SAPTeam.EasySign.CommandLine
1010
public abstract partial class CommandProvider<T>
1111
where T : Bundle
1212
{
13-
public T Bundle { get; protected set; }
14-
13+
/// <summary>
14+
/// Gets or sets the bundle.
15+
/// </summary>
16+
public T? Bundle { get; protected set; }
17+
18+
/// <summary>
19+
/// Initializes the bundle with the specified working directory and bundle name.
20+
/// </summary>
21+
/// <param name="workingDirectory">The working directory.</param>
22+
/// <param name="bundleName">The bundle name.</param>
1523
public abstract void InitializeBundle(string workingDirectory, string bundleName);
1624

25+
/// <summary>
26+
/// Runs the add command.
27+
/// </summary>
28+
/// <param name="statusContext">The status context for interacting with <see cref="AnsiConsole.Status"/>.</param>
1729
protected virtual void RunAdd(StatusContext statusContext)
1830
{
1931
if (Bundle == null)
@@ -35,6 +47,11 @@ protected virtual void RunAdd(StatusContext statusContext)
3547
Bundle.Update();
3648
}
3749

50+
/// <summary>
51+
/// Runs the sign command.
52+
/// </summary>
53+
/// <param name="statusContext">The status context for interacting with <see cref="AnsiConsole.Status"/>.</param>
54+
/// <param name="certificates">The certificates.</param>
3855
protected virtual void RunSign(StatusContext statusContext, X509Certificate2Collection certificates)
3956
{
4057
if (Bundle == null)
@@ -80,6 +97,10 @@ protected virtual void RunSign(StatusContext statusContext, X509Certificate2Coll
8097
Bundle.Update();
8198
}
8299

100+
/// <summary>
101+
/// Runs the verify command.
102+
/// </summary>
103+
/// <param name="statusContext">The status context for interacting with <see cref="AnsiConsole.Status"/>.</param>
83104
protected virtual void RunVerify(StatusContext statusContext)
84105
{
85106
if (Bundle == null)
@@ -200,6 +221,11 @@ protected virtual void RunVerify(StatusContext statusContext)
200221
AnsiConsole.MarkupLine("[green]Bundle Verification Completed Successfully[/]");
201222
}
202223

224+
/// <summary>
225+
/// Verifies the validity of a certificate.
226+
/// </summary>
227+
/// <param name="certificate">The certificate to verify.</param>
228+
/// <returns>True if the certificate is valid; otherwise, false.</returns>
203229
protected bool VerifyCertificate(X509Certificate2 certificate)
204230
{
205231
if (Bundle == null)

src/EasySign.CommandLine/CommandProvider.cs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,40 @@
88

99
namespace SAPTeam.EasySign.CommandLine
1010
{
11+
/// <summary>
12+
/// Provides command definitions and handlers for the EasySign command line interface.
13+
/// </summary>
14+
/// <typeparam name="T">The type of the bundle.</typeparam>
1115
public abstract partial class CommandProvider<T>
1216
{
17+
/// <summary>
18+
/// Gets the common argument for the working directory.
19+
/// </summary>
1320
protected Argument<string> WorkingDirectory { get; } = new Argument<string>("directory", "Working directory");
1421

22+
/// <summary>
23+
/// Gets the common option for the bundle file name.
24+
/// </summary>
1525
protected Option<string> BundleName { get; } = new Option<string>("-f", () => ".eSign", "Bundle file name");
1626

27+
/// <summary>
28+
/// Gets the root command for the command line interface.
29+
/// </summary>
30+
/// <returns>The root command.</returns>
1731
public abstract RootCommand GetRootCommand();
1832

33+
/// <summary>
34+
/// Gets the command for creating a new bundle or updating an existing one.
35+
/// </summary>
1936
public Command Add
2037
{
2138
get
2239
{
2340
var command = new Command("add", "Create new bundle or update an existing one")
24-
{
25-
WorkingDirectory,
26-
BundleName,
27-
};
41+
{
42+
WorkingDirectory,
43+
BundleName,
44+
};
2845

2946
command.SetHandler((workingDir, bundleName) =>
3047
{
@@ -36,6 +53,9 @@ public Command Add
3653
}
3754
}
3855

56+
/// <summary>
57+
/// Gets the command for signing bundle with one or more certificate.
58+
/// </summary>
3959
public Command Sign
4060
{
4161
get
@@ -45,13 +65,13 @@ public Command Sign
4565
var pfxNoPassOpt = new Option<bool>("--no-password", "Ignore PFX File password prompt");
4666

4767
var command = new Command("sign", "Sign bundle with certificate")
48-
{
49-
WorkingDirectory,
50-
BundleName,
51-
pfxOpt,
52-
pfxPassOpt,
53-
pfxNoPassOpt,
54-
};
68+
{
69+
WorkingDirectory,
70+
BundleName,
71+
pfxOpt,
72+
pfxPassOpt,
73+
pfxNoPassOpt,
74+
};
5575

5676
command.SetHandler((workingDir, bundleName, pfxFilePath, pfxFilePassword, pfxNoPasswordPrompt) =>
5777
{
@@ -65,15 +85,18 @@ public Command Sign
6585
}
6686
}
6787

88+
/// <summary>
89+
/// Gets the command for verifying bundle.
90+
/// </summary>
6891
public Command Verify
6992
{
7093
get
7194
{
7295
var command = new Command("verify", "Verify bundle")
73-
{
74-
WorkingDirectory,
75-
BundleName,
76-
};
96+
{
97+
WorkingDirectory,
98+
BundleName,
99+
};
77100

78101
command.SetHandler((workingDir, bundleName) =>
79102
{

src/EasySign.CommandLine/Utils.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99

1010
namespace SAPTeam.EasySign.CommandLine
1111
{
12+
/// <summary>
13+
/// Provides utility methods for various operations.
14+
/// </summary>
1215
public static class Utils
1316
{
17+
/// <summary>
18+
/// Runs the specified action within a status context, provides fancy progress showing.
19+
/// </summary>
20+
/// <param name="action">The action to run within the status context.</param>
1421
public static void RunInStatusContext(Action<StatusContext> action)
1522
{
1623
AnsiConsole.Status()
@@ -19,6 +26,12 @@ public static void RunInStatusContext(Action<StatusContext> action)
1926
.Start("", action);
2027
}
2128

29+
/// <summary>
30+
/// Safely enumerates files in the specified path that match the search pattern.
31+
/// </summary>
32+
/// <param name="path">The path to search for files.</param>
33+
/// <param name="searchPattern">The search pattern to match files.</param>
34+
/// <returns>An enumerable collection of file paths.</returns>
2235
public static IEnumerable<string> SafeEnumerateFiles(string path, string searchPattern)
2336
{
2437
ConcurrentQueue<string> folders = new();
@@ -57,6 +70,13 @@ public static IEnumerable<string> SafeEnumerateFiles(string path, string searchP
5770
}
5871
}
5972

73+
/// <summary>
74+
/// Retrieves a collection of certificates from a PFX file or the current user's certificate store.
75+
/// </summary>
76+
/// <param name="pfxFilePath">The path to the PFX file.</param>
77+
/// <param name="pfxFilePassword">The password for the PFX file.</param>
78+
/// <param name="pfxNoPasswordPrompt">Indicates whether to prompt for a password if not provided.</param>
79+
/// <returns>A collection of certificates.</returns>
6080
public static X509Certificate2Collection GetCertificates(string pfxFilePath, string pfxFilePassword, bool pfxNoPasswordPrompt)
6181
{
6282
X509Certificate2Collection collection = new();
@@ -66,7 +86,7 @@ public static X509Certificate2Collection GetCertificates(string pfxFilePath, str
6686
string pfpass = !string.IsNullOrEmpty(pfxFilePassword) ? pfxFilePassword : !pfxNoPasswordPrompt ? SecurePrompt("Enter PFX File password (if needed): ") : "";
6787

6888
#if NET9_0_OR_GREATER
69-
var tempCollection = X509CertificateLoader.LoadPkcs12CollectionFromFile(pfxFilePath, pfpass, X509KeyStorageFlags.EphemeralKeySet);
89+
var tempCollection = X509CertificateLoader.LoadPkcs12CollectionFromFile(pfxFilePath, pfpass, X509KeyStorageFlags.EphemeralKeySet);
7090
#else
7191
var tempCollection = new X509Certificate2Collection();
7292
tempCollection.Import(pfxFilePath, pfpass, X509KeyStorageFlags.EphemeralKeySet);
@@ -105,6 +125,11 @@ public static X509Certificate2Collection GetCertificates(string pfxFilePath, str
105125
return collection;
106126
}
107127

128+
/// <summary>
129+
/// Prompts the user for input securely, hiding the input as it is typed.
130+
/// </summary>
131+
/// <param name="prompt">The prompt message to display.</param>
132+
/// <returns>The user input.</returns>
108133
public static string SecurePrompt(string prompt)
109134
{
110135
return AnsiConsole.Prompt(
@@ -114,6 +139,10 @@ public static string SecurePrompt(string prompt)
114139
.Secret(null));
115140
}
116141

142+
/// <summary>
143+
/// Enumerates and displays the statuses of an X509 certificate chain.
144+
/// </summary>
145+
/// <param name="statuses">The array of X509 chain statuses.</param>
117146
public static void EnumerateStatuses(X509ChainStatus[] statuses)
118147
{
119148
foreach (var status in statuses)

0 commit comments

Comments
 (0)