Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Modify how CLI options are added to a command (#16)
Browse files Browse the repository at this point in the history
* Modify how options are added for CSharpInitCommand

* Modify how options are added for CSharpAddProjectCommand
  • Loading branch information
Smalls1652 authored May 19, 2024
1 parent 1fc829b commit 73f94bf
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,81 @@ public CSharpAddProjectCommand() : base("add-project")
{
Description = "Add a new C# project to the workspace.";

Options.Add(
Options
.AddSolutionFilePathOption()
.AddProjectPathOption()
.AddProjectFriendlyNameOption()
.AddIsRunnableOption()
.AddIsWatchableOption();

Action = new CSharpAddProjectCommandAction();
}
}

file static class CSharpAddProjectCommandExtensions
{
/// <summary>
/// Add '--solution-file-path' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddSolutionFilePathOption(this IList<CliOption> options)
{
options.Add(
new CliOption<string>("--solution-file-path")
{
Description = "The solution file to add the project to.",
Required = false
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--project-path' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddProjectPathOption(this IList<CliOption> options)
{
options.Add(
new CliOption<string>("--project-path")
{
Description = "The path to the project.",
Required = true
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--project-friendly-name' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddProjectFriendlyNameOption(this IList<CliOption> options)
{
options.Add(
new CliOption<string>("--project-friendly-name")
{
Description = "The friendly name of the project.",
Required = false
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--is-runnable' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddIsRunnableOption(this IList<CliOption> options)
{
options.Add(
new CliOption<bool>("--is-runnable")
{
Description = "Whether the project is runnable.",
Expand All @@ -47,7 +97,17 @@ public CSharpAddProjectCommand() : base("add-project")
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--is-watchable' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddIsWatchableOption(this IList<CliOption> options)
{
options.Add(
new CliOption<bool>("--is-watchable")
{
Description = "Whether the project is watchable.",
Expand All @@ -56,6 +116,6 @@ public CSharpAddProjectCommand() : base("add-project")
}
);

Action = new CSharpAddProjectCommandAction();
return options;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ public CSharpInitCommand() : base("init")
{
Description = "Initialize a new C# project.";

Options.Add(
Options
.AddOutputDirectoryOption()
.AddSolutionNameOption()
.AddGitVersionOption()
.AddNuGetConfigOption()
.AddCentrallyManagedPackagesOption()
.AddCSharpLspOption();

Action = new CSharpInitCommandAction();
}
}

file static class CSharpInitCommandExtensions
{
/// <summary>
/// Add '--output-directory' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddOutputDirectoryOption(this IList<CliOption> options)
{
options.Add(
new CliOption<string>("--output-directory")
{
Description = "The output directory for the new project.",
Expand All @@ -24,15 +45,35 @@ public CSharpInitCommand() : base("init")
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--solution-name' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddSolutionNameOption(this IList<CliOption> options)
{
options.Add(
new CliOption<string>("--solution-name")
{
Description = "The default solution file.",
Required = false
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--add-gitversion' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddGitVersionOption(this IList<CliOption> options)
{
options.Add(
new CliOption<bool>("--add-gitversion")
{
Description = "Whether to add GitVersion to the new project.",
Expand All @@ -41,7 +82,17 @@ public CSharpInitCommand() : base("init")
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--add-nuget-config' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddNuGetConfigOption(this IList<CliOption> options)
{
options.Add(
new CliOption<bool>("--add-nuget-config")
{
Description = "Whether to add a NuGet.Config file to the new project.",
Expand All @@ -50,7 +101,17 @@ public CSharpInitCommand() : base("init")
}
);

Options.Add(
return options;
}

/// <summary>
/// Add '--enable-centrally-managed-packages' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddCentrallyManagedPackagesOption(this IList<CliOption> options)
{
options.Add(
new CliOption<bool>("--enable-centrally-managed-packages")
{
Description = "Whether to enable centrally managed packages.",
Expand All @@ -59,6 +120,16 @@ public CSharpInitCommand() : base("init")
}
);

return options;
}

/// <summary>
/// Add '--csharp-lsp' option to the command.
/// </summary>
/// <param name="options">The options to add to.</param>
/// <returns>The <see cref="IList{T}"/> for chaining.</returns>
public static IList<CliOption> AddCSharpLspOption(this IList<CliOption> options)
{
CliOption<string> lspOption = new("--csharp-lsp")
{
Description = "The C# language server to use.",
Expand All @@ -78,8 +149,8 @@ public CSharpInitCommand() : base("init")
}
);

Options.Add(lspOption);
options.Add(lspOption);

Action = new CSharpInitCommandAction();
return options;
}
}

0 comments on commit 73f94bf

Please sign in to comment.