|
1 | | -using System.Runtime.InteropServices; |
| 1 | +using System.CommandLine; |
| 2 | +using System.Runtime.InteropServices; |
2 | 3 | using System.Text; |
3 | 4 | using Devlooped; |
| 5 | +using DotNetConfig; |
4 | 6 | using GitCredentialManager.UI; |
5 | 7 | using Spectre.Console; |
6 | 8 |
|
|
15 | 17 | args = [.. args.Where(x => x != "--aot")]; |
16 | 18 | } |
17 | 19 |
|
| 20 | +var config = Config.Build(Config.GlobalLocation); |
| 21 | +if (args.Length > 0 && config.GetString("runcs", args[0]) is string aliased) |
| 22 | + args = [aliased, .. args[1..]]; |
| 23 | + |
| 24 | +// Set alias and remove from args if present |
| 25 | +var option = new Option<string?>("--alias"); |
| 26 | +var parsed = new RootCommand() { Options = { option } }.Parse(args); |
| 27 | +var alias = parsed.GetValue(option); |
| 28 | +if (alias != null) |
| 29 | + args = [.. parsed.UnmatchedTokens]; |
| 30 | + |
18 | 31 | if (args.Length == 0 || !RemoteRef.TryParse(args[0], out var location)) |
19 | 32 | { |
20 | 33 | AnsiConsole.MarkupLine( |
21 | 34 | $""" |
22 | 35 | Usage: |
23 | | - [grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [bold]<repoRef>[/] [grey italic][[<appArgs>...]][/] |
| 36 | + [grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [grey][[--alias ALIAS]][/] [bold]<repoRef>[/] [grey italic][[<appArgs>...]][/] |
24 | 37 |
|
25 | 38 | Arguments: |
26 | 39 | [bold]<REPO_REF>[/] Reference to remote file to run, with format [yellow][[host/]]owner/repo[[@ref]][[:path]][/] |
|
33 | 46 | * gitlab.com/kzu/sandbox@main:run.cs (all explicit parts) |
34 | 47 | * kzu/sandbox (implied host github.com, ref and path defaults) |
35 | 48 | |
| 49 | + Can be an alias previously set with --alias. |
| 50 | +
|
36 | 51 | [bold]<appArgs>[/] Arguments passed to the C# program that is being run. |
37 | 52 |
|
38 | 53 | Options: |
39 | | - [bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false. |
| 54 | + [bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false. |
| 55 | + [bold]--alias[/] ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref. |
40 | 56 | """); |
41 | 57 | return; |
42 | 58 | } |
43 | 59 |
|
| 60 | +if (alias != null) |
| 61 | + config = config.SetString("runcs", alias, location.ToString()); |
| 62 | + |
44 | 63 | // Create the dispatcher on the main thread. This is required |
45 | 64 | // for some platform UI services such as macOS that mandates |
46 | 65 | // all controls are created/accessed on the initial thread |
|
50 | 69 | // Run AppMain in a new thread and keep the main thread free |
51 | 70 | // to process the dispatcher's job queue. |
52 | 71 | var main = Task |
53 | | - .Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName) |
| 72 | + .Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName, config) |
54 | 73 | .RunAsync(args[1..], aot)) |
55 | 74 | .ContinueWith(t => |
56 | 75 | { |
|
0 commit comments