|
1 | 1 | using System.CommandLine; |
| 2 | +using System.Diagnostics; |
2 | 3 | using System.Runtime.InteropServices; |
3 | 4 | using System.Text; |
4 | 5 | using Devlooped; |
|
11 | 12 |
|
12 | 13 | // Default PublishAot=false since it severely limits the code that can run (i.e. no reflection, STJ even) |
13 | 14 | var aot = false; |
14 | | -if (args.Any(x => x == "--aot")) |
| 15 | +if (args.Any(x => x is "--aot" or "--dnx-aot")) |
15 | 16 | { |
16 | 17 | aot = true; |
17 | | - args = [.. args.Where(x => x != "--aot")]; |
| 18 | + args = [.. args.Where(x => x is not "--aot" and not "--dnx-aot")]; |
| 19 | +} |
| 20 | + |
| 21 | +// --dnx-debug to launch debugger before running |
| 22 | +var debug = false; |
| 23 | +if (args.Any(x => x == "--dnx-debug")) |
| 24 | +{ |
| 25 | + debug = true; |
| 26 | + args = [.. args.Where(x => x != "--dnx-debug")]; |
| 27 | +} |
| 28 | + |
| 29 | +// --dnx-force to skip ETag checking |
| 30 | +var force = false; |
| 31 | +if (args.Any(x => x == "--dnx-force")) |
| 32 | +{ |
| 33 | + force = true; |
| 34 | + args = [.. args.Where(x => x != "--dnx-force")]; |
18 | 35 | } |
19 | 36 |
|
20 | 37 | var config = Config.Build(Config.GlobalLocation); |
21 | 38 | if (args.Length > 0 && config.GetString("runfile", args[0]) is string aliased) |
22 | 39 | args = [aliased, .. args[1..]]; |
23 | 40 |
|
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); |
| 41 | +// Set alias and remove from args if present (--alias or --dnx-alias) |
| 42 | +var aliasOption = new Option<string?>(["--alias", "--dnx-alias"]); |
| 43 | +var parsed = new RootCommand() { Options = { aliasOption } }.Parse(args); |
| 44 | +var alias = parsed.GetValue(aliasOption); |
28 | 45 | if (alias != null) |
29 | 46 | args = [.. parsed.UnmatchedTokens]; |
30 | 47 |
|
|
33 | 50 | AnsiConsole.MarkupLine( |
34 | 51 | $""" |
35 | 52 | Usage: |
36 | | - [grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [grey][[--alias ALIAS]][/] [bold]<repoRef>[/] [grey italic][[<appArgs>...]][/] |
| 53 | + [grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[OPTIONS]][/] [bold]<repoRef>[/] [grey italic][[<appArgs>...]][/] |
37 | 54 |
|
38 | 55 | Arguments: |
39 | 56 | [bold]<REPO_REF>[/] Reference to remote file to run, with format [yellow][[host/]]owner/repo[[@ref]][[:path]][/] |
|
46 | 63 | * gitlab.com/kzu/sandbox@main:run.cs (all explicit parts) |
47 | 64 | * kzu/sandbox (implied host github.com, ref and path defaults) |
48 | 65 | |
49 | | - If --alias was used in a previous run, the alias can be used instead of the full ref. |
| 66 | + If --dnx-alias was used in a previous run, the alias can be used instead of the full ref. |
50 | 67 |
|
51 | 68 | [bold]<appArgs>[/] Arguments passed to the C# program that is being run. |
52 | 69 |
|
53 | 70 | Options: |
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. |
| 71 | + [bold]--dnx-aot[/] Enable dotnet AOT defaults for run file.cs. Defaults to false. |
| 72 | + [bold]--dnx-alias[/] ALIAS Assign an alias on first usage which can be used instead of the full ref. |
| 73 | + [bold]--dnx-debug[/] Launch the debugger before running. |
| 74 | + [bold]--dnx-force[/] Force download, skipping ETag checking. |
56 | 75 | """); |
57 | 76 | return; |
58 | 77 | } |
59 | 78 |
|
60 | 79 | if (alias != null) |
61 | 80 | config = config.SetString("runfile", alias, location.ToString()); |
62 | 81 |
|
| 82 | +// Launch debugger if --dnx-debug was specified |
| 83 | +if (debug) |
| 84 | + Debugger.Launch(); |
| 85 | + |
63 | 86 | // Create the dispatcher on the main thread. This is required |
64 | 87 | // for some platform UI services such as macOS that mandates |
65 | 88 | // all controls are created/accessed on the initial thread |
|
70 | 93 | // to process the dispatcher's job queue. |
71 | 94 | var main = Task |
72 | 95 | .Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName, config) |
73 | | - .RunAsync(args[1..], aot)) |
| 96 | + .RunAsync(args[1..], aot, force)) |
74 | 97 | .ContinueWith(t => |
75 | 98 | { |
76 | 99 | Dispatcher.MainThread.Shutdown(); |
|
0 commit comments