Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the command line parser and parse the tool arguments #3

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VSConfigFinder/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
csharp_using_directive_placement = outside_namespace:silent
csharp_using_directive_placement = inside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
Expand Down
25 changes: 13 additions & 12 deletions VSConfigFinder/CommandLineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
namespace VSConfigFinder
{
internal class CommandLineOptions : ICommandLineOptions
{
public CommandLineOptions(string filePath, string output)
{
Utilities.ValidateIsNotNullOrEmpty(filePath, nameof(filePath));
Utilities.ValidateOutputParameter(output, nameof(output));

FilePath = filePath;
Output = output;
}
using CommandLine;

public string FilePath { get; set; }
/// <inheritdoc/>
public class CommandLineOptions : ICommandLineOptions
{
/// <inheritdoc/>
[Option("folderpath", Required = true, HelpText = "Set the source folder path to use as the root. The search will start from the root towards the bottom.")]
public string FolderPath { get; set; }

public string Output { get; set; }
/// <inheritdoc/>
[Option("createfile", Required = false, HelpText = "Set the folder path to output the consolidated .vsconfig.\n" +
"If the argument (--createfile) is not passed at all, the program will output the cli arguments that can be fed into the Visual Studio Installer setup arguments. (e.g. --add Microsoft.VisualStudio.Component.Roslyn.Compiler Microsoft.Net.Component.4.8.SDK)\n" +
"If the argument is passed without a following folder path, the program will create and output the final .vsconfig into the current directory.\n" +
"If the argument is passed with a following folder path, the program will create and output the final .vsconfig into the specified folder path that is followed by --createFile.")]
public string? CreateFile { get; set; }
}
}
16 changes: 13 additions & 3 deletions VSConfigFinder/ICommandLineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
namespace VSConfigFinder
{
internal interface ICommandLineOptions
/// <summary>
/// The interface for the command line options.
/// </summary>
public interface ICommandLineOptions
{
string FilePath { get; set; }
/// <summary>
/// Gets or sets the folder path to be used as the root (starting point) of the search.
/// </summary>
string FolderPath { get; set; }

string Output { get; set; }
/// <summary>
/// Gets or sets the folder path to output the consolidated .vsconfig instead of the command line arguments.
/// If a folder path is not provided after the argument, the output folder will default to the current directory.
/// </summary>
string? CreateFile { get; set; }
}
}
37 changes: 32 additions & 5 deletions VSConfigFinder/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
internal class Program
namespace VSConfigFinder
{
private static void Main(string[] args)
using CommandLine;

/// <summary>
/// <see cref="Program"/> class for the .vsconfig finder tool.
/// </summary>
public class Program
{
// Take in the command line arguments
/// <summary>
/// Main entry point of the tool.
/// </summary>
/// <param name="args">The program arguments</param>
public static void Main(string[] args)
{
var parser = new Parser(with =>
{
with.CaseSensitive = false;
});

// Take in the command line arguments
parser.ParseArguments<CommandLineOptions>(args)
.WithParsed(Run)
.WithNotParsed(HandleParseError);
}

// Create a runner
private static void Run(CommandLineOptions options)
{
Console.WriteLine("Hello! I succeeded!");
Console.WriteLine($"--createFile: {options.CreateFile}");
}

// Run and output
private static void HandleParseError(IEnumerable<Error> errors)
{
Console.WriteLine("Oops, failed");
}
}
}
4 changes: 4 additions & 0 deletions VSConfigFinder/VSConfigFinder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<None Include="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder\.editorconfig" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>

This file was deleted.

23 changes: 0 additions & 23 deletions VSConfigFinder/obj/Debug/net7.0/VSConfigFinder.AssemblyInfo.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
64 changes: 0 additions & 64 deletions VSConfigFinder/obj/VSConfigFinder.csproj.nuget.dgspec.json

This file was deleted.

15 changes: 0 additions & 15 deletions VSConfigFinder/obj/VSConfigFinder.csproj.nuget.g.props

This file was deleted.

2 changes: 0 additions & 2 deletions VSConfigFinder/obj/VSConfigFinder.csproj.nuget.g.targets

This file was deleted.

69 changes: 0 additions & 69 deletions VSConfigFinder/obj/project.assets.json

This file was deleted.

8 changes: 0 additions & 8 deletions VSConfigFinder/obj/project.nuget.cache

This file was deleted.