Skip to content

Commit 1d3af5e

Browse files
committed
[WIP] Improve CLI options
1 parent c6fbbca commit 1d3af5e

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

src/nugraph/GraphCommand.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ protected override async Task<int> ExecuteAsync(CommandContext commandContext, G
5151
if (graphUrl != null)
5252
{
5353
var url = graphUrl.ToString();
54-
// Using "console.WriteLine(url)" (lowercase c) would insert newlines at the physical console length, making the written URL neither copyable nor clickable
55-
// At that point the status has terminated so it's fine not using the IAnsiConsole methods
56-
await stdOut.WriteLineAsync(url);
57-
if (!settings.NoBrowser)
54+
if (settings.UrlAction.HasFlag(UrlAction.print))
55+
{
56+
// Using "console.WriteLine(url)" (lowercase c) would insert newlines at the physical console length, making the written URL neither copyable nor clickable
57+
// At that point the status has terminated so it's fine not using the IAnsiConsole methods
58+
await stdOut.WriteLineAsync(url);
59+
}
60+
if (settings.UrlAction.HasFlag(UrlAction.open))
5861
{
5962
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
6063
}

src/nugraph/GraphCommandSettings.cs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212

1313
namespace nugraph;
1414

15+
[Flags]
16+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Better fit for command line options")]
17+
internal enum UrlAction
18+
{
19+
nothing = 0,
20+
open = 1 << 0,
21+
print = 1 << 1,
22+
}
23+
1524
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global", Justification = "Required for Spectre.Console.Cli binding")]
1625
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "Required for Spectre.Console.Cli binding")]
1726
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "Instantiated by Spectre.Console.Cli through reflection")]
@@ -21,64 +30,74 @@ internal sealed class GraphCommandSettings : CommandSettings
2130
public const string DefaultTitle = "Dependency graph of [SOURCE]";
2231

2332
[CommandArgument(0, "[SOURCE]")]
24-
[Description("The source of the graph. Can be either a directory containing a .NET project, a .NET project file (csproj/fsproj/vbproj) or the name of a NuGet package, " +
25-
"optionally with a specific version, e.g. [b]Newtonsoft.Json/13.0.3[/].")]
33+
[Description("The source of the graph\n" +
34+
"Can be either\n" +
35+
" * the name of a NuGet package, optionally with a specific version, e.g. [b]Newtonsoft.Json/13.0.3[/]\n" +
36+
" * a .NET project file (csproj/fsproj/vbproj)\n" +
37+
" * a directory containing a .NET project\n")]
2638
public string? SourceInput { get; init; }
2739

2840
public FileOrPackage? Source { get; private set; }
2941

30-
[CommandOption("-o|--output <OUTPUT>")]
31-
[Description("The path to the dependency graph output file. If not specified, the dependency graph URL is written on the standard output and an online service is opened in the default browser.")]
32-
public FileInfo? OutputFile { get; init; }
33-
3442
[CommandOption("-f|--framework <FRAMEWORK>")]
35-
[Description("The target framework to consider when building the dependency graph.")]
43+
[Description("The target framework to consider when building the dependency graph\n" +
44+
"See https://learn.microsoft.com/en-us/dotnet/standard/frameworks#supported-target-frameworks for the list of supported target frameworks")]
3645
[TypeConverter(typeof(NuGetFrameworkConverter))]
3746
public NuGetFramework? Framework { get; init; }
3847

3948
[CommandOption("-r|--runtime <RUNTIME_IDENTIFIER>")]
40-
[Description("The target runtime to consider when building the dependency graph.")]
49+
[Description("The target runtime to consider when building the dependency graph\n" +
50+
"See https://learn.microsoft.com/en-us/dotnet/core/rid-catalog#known-rids for the list of known runtime identifiers")]
4151
public string? RuntimeIdentifier { get; init; }
4252

53+
[CommandOption("-o|--output <OUTPUT>")]
54+
[Description("The path to the dependency graph output file\n" +
55+
"If not specified, the default web browser is used to render the dependency graph using an online service\n" +
56+
"See also the [b]--format[/] and [b]--url[/] options")]
57+
public FileInfo? OutputFile { get; init; }
58+
4359
[CommandOption("-m|--format <FORMAT>")]
44-
[Description($"The format to use when the [b]--output[/] option is not specified.\n" +
60+
[Description($"The format to use when the [b]--output[/] option is not specified\n" +
4561
$"Use [b]mmd[/] or [b]mermaid[/] for Mermaid Live Editor https://mermaid.live\n" +
4662
$"Use [b]dot[/], [b]gv[/] or [b]graphviz[/] for Edotor https://edotor.net\n" +
47-
"See https://github.com/0xced/nugraph/#output for even more supported formats.")]
63+
"See https://github.com/0xced/nugraph/#output for even more supported formats")]
4864
[DefaultValue("mermaid")]
4965
public string Format { get; init; } = "";
5066

5167
public OnlineService Service { get; private set; }
5268

69+
[CommandOption("-u|--url")]
70+
[Description("Defines what to do when the [b]--output[/] option is not specified\n" +
71+
"Use [b]open[/] for rendering the dependency graph using an online service or [b]print[/] for printing the graph URL on the standard output without opening the browser\n" +
72+
"Both options can be combined with a comma, i.e. [b]open,print[/] to both open the URL and print it")]
73+
[DefaultValue(UrlAction.open)]
74+
public UrlAction UrlAction { get; init; }
75+
5376
[CommandOption("-d|--direction <GRAPH_DIRECTION>")]
54-
[Description($"The direction of the dependency graph. Possible values are [b]{nameof(GraphDirection.LeftToRight)}[/] and [b]{nameof(GraphDirection.TopToBottom)}[/]")]
77+
[Description($"The direction of the dependency graph, possible values are [b]{nameof(GraphDirection.LeftToRight)}[/] (recommended for large graphs) and [b]{nameof(GraphDirection.TopToBottom)}[/] (good for small graphs)")]
5578
[DefaultValue(GraphDirection.LeftToRight)]
5679
public GraphDirection GraphDirection { get; init; }
5780

5881
[CommandOption("-t|--title <GRAPH_TITLE>")]
59-
[Description("The title of the dependency graph.")]
82+
[Description("The title of the dependency graph")]
6083
[DefaultValue(DefaultTitle)]
6184
public string Title { get; set; } = "";
6285

6386
[CommandOption("-s|--include-version")]
64-
[Description("Include package versions in the dependency graph. E.g. [b]Serilog/4.3.0[/] instead of [b]Serilog[/]")]
87+
[Description("Include package versions in the dependency graph nodes, e.g. [b]Serilog/4.3.0[/] instead of [b]Serilog[/]")]
6588
[DefaultValue(false)]
6689
public bool GraphIncludeVersions { get; init; }
6790

6891
[CommandOption("-i|--ignore <PACKAGE>")]
69-
[Description("Packages to ignore in the dependency graph. Supports * wildcards. May be used multiple times.")]
92+
[Description("Packages to ignore in the dependency graph, may be used multiple times and supports * wildcards, e.g. [b]--ignore \"System.*\"[/]")]
7093
public string[] GraphIgnore { get; init; } = [];
7194

7295
[CommandOption("--no-links")]
73-
[Description("Remove clickable links from the the dependency graph. Can be useful to reduce the size of the graph if you get \"Maximum text size in diagram exceeded\" in Mermaid Live Editor.")]
96+
[Description("Remove clickable links from the the dependency graph\n" +
97+
"Can be useful to reduce the size of the graph if it's too large and Mermaid Live Editor is returning \"Maximum text size in diagram exceeded\" ")]
7498
[DefaultValue(false)]
7599
public bool NoLinks { get; set; }
76100

77-
[CommandOption("--no-browser")]
78-
[Description("Do not open the default browser, only print the graph URL on the console when the [b]--output[/] option is not specified.")]
79-
[DefaultValue(false)]
80-
public bool NoBrowser { get; set; }
81-
82101
[CommandOption("-l|--log <LEVEL>")]
83102
[Description($"The NuGet operations log level. Possible values are [b]{nameof(LogLevel.Debug)}[/], [b]{nameof(LogLevel.Verbose)}[/], [b]{nameof(LogLevel.Information)}[/], [b]{nameof(LogLevel.Minimal)}[/], [b]{nameof(LogLevel.Warning)}[/] and [b]{nameof(LogLevel.Error)}[/]")]
84103
#if DEBUG
@@ -89,20 +108,20 @@ internal sealed class GraphCommandSettings : CommandSettings
89108
public LogLevel LogLevel { get; init; }
90109

91110
[CommandOption("--nuget-root <PATH>", IsHidden = true)]
92-
[Description("The NuGet root directory. Can be used to completely isolate nugraph from default NuGet operations.")]
111+
[Description("The NuGet root directory, can be used to completely isolate nugraph from default NuGet operations")]
93112
public string? NuGetRoot { get; init; }
94113

95114
[CommandOption("--sdk <PATH>", IsHidden = true)]
96115
[Description("Path to the .NET SDK directory. E.g. [b]/usr/local/share/dotnet/sdk/8.0.410[/]")]
97116
public DirectoryInfo? Sdk { get; init; }
98117

99118
[CommandOption("--include-ignored-packages", IsHidden = true)]
100-
[Description("Include ignored packages in the dependency graph. Used for debugging.")]
119+
[Description("Include ignored packages in the dependency graph, used for debugging")]
101120
[DefaultValue(false)]
102121
public bool GraphWriteIgnoredPackages { get; init; }
103122

104123
[CommandOption("--diagnose", IsHidden = true)]
105-
[Description("Prints diagnostics information.")]
124+
[Description("Prints diagnostics information")]
106125
[DefaultValue(false)]
107126
public bool Diagnose { get; init; }
108127

0 commit comments

Comments
 (0)