Skip to content

Commit

Permalink
#36 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
synthphonic committed May 30, 2022
1 parent fb256f0 commit 2461289
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FindPackageCommand : CommandBase
[Option(longName: "nuget-package", shortName: 'g', Required = true, HelpText = "The nuget package to find.")]
public string NugetPackage { get; set; }

[Usage(ApplicationAlias = Program.CliName)]
[Usage()]
public static IEnumerable<Example> Examples
{
get
Expand Down Expand Up @@ -54,6 +54,8 @@ internal FindPackageCommand(string solutionFileName, string nugetPackage, bool r

public async Task Run()
{
Program.DisplayProductInfo();

Colorful.Console.WriteLine();
Colorful.Console.WriteLine("Working. Please wait...", Color.GreenYellow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ListNugetPackagesCommand : CommandBase
[Option("usedebugdata", Required = false, Hidden = true, HelpText = "")]
public bool UseDebugData { get; set; }

[Usage(ApplicationAlias = Program.CliName)]
[Usage()]
public static IEnumerable<Example> Examples
{
get
Expand Down Expand Up @@ -56,6 +56,8 @@ public ListNugetPackagesCommand()

public async Task Run()
{
Program.DisplayProductInfo();

Colorful.Console.WriteLine();
Colorful.Console.WriteLine("Working. Please wait...", Color.GreenYellow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ namespace Nautilus.SolutionExplorerClient.Commands;
[Verb("list-projects", HelpText = "List out all projects that exists under a solution (.sln) file")]
internal class ListProjectsCommand : CommandBase
{
private const string Example_Text = "List out all projects under the solution";
//delegate void ShowNugetPackages(Project project);
private const string Example_Text = $"List out all projects under the solution";

[Option(longName: "solutionfile", shortName: 's', Required = true, HelpText = "The full file path to the .sln file.")]
public string SolutionFileName { get; set; }

[Option(longName: "projects-only", shortName: 'p', HelpText = "Process project files only and ignore the rest.")]
[Option(longName: "projects-only", shortName: 'p', Default = false, HelpText = "Process project files only and ignore the rest.")]
public bool ProjectsOnly { get; set; }

[Option(longName: "nuget-packages", shortName: 'n', Default = false, Required = false, Hidden = false, HelpText = "Display nuget packages for each project.")]
Expand All @@ -25,22 +24,22 @@ internal class ListProjectsCommand : CommandBase
public bool ShowNugetPackageUpdates { get; set; }

[Option(longName: "nuget-pre-release", Default = false, Required = false, Hidden = false, HelpText = "To fetch data for pre-release versions of a particular nuget package. " +
"This switch is used toegher with -u or --nuget-package-updates switch")]
"This switch is used toegher with -u option")]
public bool ShowPreReleaseNugetPackages { get; set; }

[Usage(ApplicationAlias = Program.CliName)]
[Usage()]
public static IEnumerable<Example> Examples
{
get
{
var platformPathSample = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
platformPathSample = "/users/itsme/xxx.sln";
platformPathSample = @"/users/itsme/mysolution.sln";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
platformPathSample = @"C:\myproject\xxx.sln";
platformPathSample = @"C:\myproject\mysolution.sln";
}

return new List<Example>
Expand All @@ -57,6 +56,8 @@ public ListProjectsCommand()

internal async Task Run()
{
Program.DisplayProductInfo();

var slnFileReader = new SolutionFileReader(SolutionFileName, ProjectsOnly);
Solution solution = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ModifyProjectVersionCommand : CommandBase
[Option(longName: "restore-version", shortName: 'r', Required = false, HelpText = "Restore the version number to its original state.")]
public bool RestoreVersionNumber { get; set; }

[Usage(ApplicationAlias = Program.CliName)]
[Usage()]
public static IEnumerable<Example> Examples
{
get
Expand Down Expand Up @@ -58,7 +58,7 @@ public ModifyProjectVersionCommand()

public async Task Run()
{
await Task.CompletedTask;
Program.DisplayProductInfo();

Colorful.Console.WriteLine();
Colorful.Console.WriteLine("Working. Please wait...", Color.GreenYellow);
Expand All @@ -80,8 +80,7 @@ public async Task Run()
project.Update("Version", VersionNumber);
}

//Console.WriteLine($"-b {Backup}");
//Console.WriteLine($"-r {RestoreVersionNumber}");
await Task.CompletedTask;
}

internal static void Execute(ModifyProjectVersionCommand command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UpdateNugetPackageCommand : CommandBase
[Option(longName: "nuget-version", shortName: 'g', Required = true, HelpText = "The nuget package version to upate to.")]
public string NugetVersion { get; set; }

[Usage(ApplicationAlias = Program.CliName)]
[Usage()]
public static IEnumerable<Example> Examples
{
get
Expand Down Expand Up @@ -62,6 +62,8 @@ public UpdateNugetPackageCommand()

internal async Task Run()
{
Program.DisplayProductInfo();

var solution = ReadSolutionStructure();

if (ProjectName.ToUpper().Equals("ALL") || ProjectName.ToLower().Equals("all"))
Expand Down
3 changes: 2 additions & 1 deletion src/Nautilus.SolutionExplorerClient/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
global using System.Diagnostics;
global using System.Drawing;
global using System.Linq;
global using System.Reflection;
global using System.Runtime.InteropServices;
global using System.Threading.Tasks;
global using CommandLine;
Expand All @@ -15,11 +16,11 @@
global using Nautilus.SolutionExplorer.Core.Exceptions;
global using Nautilus.SolutionExplorer.Core.Extensions;
global using Nautilus.SolutionExplorer.Core.FileReaders;
global using Nautilus.SolutionExplorer.Core.Logging;
global using Nautilus.SolutionExplorer.Core.Models;
global using Nautilus.SolutionExplorer.Core.Models.Http;
global using Nautilus.SolutionExplorer.Core.TestData;
global using Nautilus.SolutionExplorerClient.Commands;
global using Nautilus.SolutionExplorerClient.Commands.Layout;
global using Nautilus.SolutionExplorerClient.Constants;
global using Nautilus.SolutionExplorerClient.Core;
global using Nautilus.SolutionExplorer.Core.Logging;
79 changes: 61 additions & 18 deletions src/Nautilus.SolutionExplorerClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,73 @@

class Program
{
internal const string CliName = $"nsmgr";

static void Main(string[] args)
{
string[] internalArgs;
if (args.Length == 0)
{
internalArgs = "--help".Split();
}
else
{
internalArgs = args;
}

CommandlineStartup(internalArgs);
}

static void CommandlineStartup(string[] args)
{

#if DEBUG
TestDataHelper.UseTestData = false;
#endif

_ = Parser.Default.ParseArguments<FindPackageCommand, ListProjectsCommand, ListNugetPackagesCommand, UpdateNugetPackageCommand, ModifyProjectVersionCommand>(args)
.WithParsed((Action<UpdateNugetPackageCommand>)((command) => UpdateNugetPackageCommand.Execute(command)))
.WithParsed((Action<ListProjectsCommand>)((command) => ListProjectsCommand.Execute(command)))
.WithParsed((Action<ListNugetPackagesCommand>)((command) => ListNugetPackagesCommand.Execute(command)))
.WithParsed((Action<FindPackageCommand>)((command) => FindPackageCommand.Execute(command)))
.WithParsed((Action<ModifyProjectVersionCommand>)((command) => ModifyProjectVersionCommand.Execute(command)))
.WithNotParsed(errs =>
{
//var sb = new StringBuilder();
//foreach (var item in errs)
//{
// sb.AppendFormat($"{item.ToString()}");
//}
//Console.WriteLine(sb.ToString());
});
var parser = new Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments<FindPackageCommand, ListProjectsCommand, ListNugetPackagesCommand, UpdateNugetPackageCommand, ModifyProjectVersionCommand>(args);
parserResult
.WithParsed<UpdateNugetPackageCommand>(options => UpdateNugetPackageCommand.Execute(options))
.WithParsed<ListProjectsCommand>(options => ListProjectsCommand.Execute(options))
.WithParsed<ListNugetPackagesCommand>(options => ListNugetPackagesCommand.Execute(options))
.WithParsed<FindPackageCommand>(options => FindPackageCommand.Execute(options))
.WithParsed<ModifyProjectVersionCommand>(options => ModifyProjectVersionCommand.Execute(options))
.WithNotParsed(errs => DisplayHelp(parserResult, errs));
}

private static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errors)
{
var helpText = HelpText.AutoBuild(result, h =>
{
var assemblyTitle = (AssemblyTitleAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false).FirstOrDefault();
var assemblyProduct = (AssemblyProductAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false).FirstOrDefault();
var assemblyDescription = (AssemblyDescriptionAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false).FirstOrDefault();
var assemblyCopyright = (AssemblyCopyrightAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).FirstOrDefault();
var assemblyInfoVersion = (AssemblyInformationalVersionAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();
h.AdditionalNewLineAfterOption = false;
h.Heading = $"{assemblyTitle.Title} v{assemblyInfoVersion.InformationalVersion}\n{assemblyProduct.Product}";
h.Copyright = $"{assemblyCopyright.Copyright}";
h.AddDashesToOption = true;
h.AddNewLineBetweenHelpSections = true;
h.AdditionalNewLineAfterOption = true;
return HelpText.DefaultParsingErrorsHandler(result, h);
}, e => e, verbsIndex: true, maxDisplayWidth: 150);

Console.WriteLine(helpText);
}

internal static void DisplayProductInfo()
{
var assemblyTitle = (AssemblyTitleAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false).FirstOrDefault();
var assemblyProduct = (AssemblyProductAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false).FirstOrDefault();
var assemblyDescription = (AssemblyDescriptionAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false).FirstOrDefault();
var assemblyCopyright = (AssemblyCopyrightAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).FirstOrDefault();
var assemblyInfoVersion = (AssemblyInformationalVersionAttribute)typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();

Console.WriteLine($"{assemblyTitle.Title} v{assemblyInfoVersion.InformationalVersion}");
Console.WriteLine($"{assemblyProduct.Product}");
Console.WriteLine($"{assemblyCopyright.Copyright}");
}
}

0 comments on commit 2461289

Please sign in to comment.