Skip to content

Commit 699306b

Browse files
Copilotkzu
andcommitted
Add --dnx-aot, --dnx-alias, --dnx-debug, --dnx-force options
Co-authored-by: kzu <169707+kzu@users.noreply.github.com>
1 parent e96bbaf commit 699306b

6 files changed

Lines changed: 106 additions & 48 deletions

File tree

readme.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Run C# code programs from git repos on GitHub, GitLab and Azure DevOps.
2828

2929
```
3030
Usage:
31-
[dnx] runfile [--aot] [--alias ALIAS] <repoRef> [<appArgs>...]
31+
[dnx] runfile [OPTIONS] <repoRef> [<appArgs>...]
3232
3333
Arguments:
3434
<REPO_REF> Reference to remote file to run, with format [host/]owner/repo[@ref][:path]
@@ -41,13 +41,15 @@ Arguments:
4141
* gitlab.com/kzu/sandbox@main:run.cs (all explicit parts)
4242
* kzu/sandbox (implied host github.com, ref and path defaults)
4343
44-
Can be an alias previously set with --alias.
44+
Can be an alias previously set with --dnx-alias.
4545
4646
<appArgs> Arguments passed to the C# program that is being run.
4747
4848
Options:
49-
--aot (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
50-
--alias ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
49+
--dnx-aot Enable dotnet AOT defaults for run file.cs. Defaults to false.
50+
--dnx-alias ALIAS Assign an alias on first usage which can be used instead of the full ref.
51+
--dnx-debug Launch the debugger before running.
52+
--dnx-force Force download, skipping ETag checking.
5153
```
5254

5355
Example:
@@ -84,7 +86,7 @@ The last download etag is used to avoid downloading on each run.
8486
Run C# code programs from GitHub gists.
8587

8688
```
87-
Usage: [dnx] gist [--aot] [--alias ALIAS] <gistRef> [<appArgs>...]
89+
Usage: [dnx] gist [OPTIONS] <gistRef> [<appArgs>...]
8890
8991
Arguments:
9092
<GIST_REF> Reference to gist file to run, with format owner/gist[@commit][:path]
@@ -95,13 +97,15 @@ Arguments:
9597
* kzu/0ac826dc7de666546aaedd38e5965381 (tip commit and program.cs or first .cs file)
9698
* kzu/0ac826dc7de666546aaedd38e5965381@d8079cf:run.cs (explicit commit and file path)
9799
98-
Can be an alias previously set with --alias.
100+
Can be an alias previously set with --dnx-alias.
99101
100102
<appArgs> Arguments passed to the C# program that is being run.
101103
102104
Options:
103-
--aot (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
104-
--alias ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
105+
--dnx-aot Enable dotnet AOT defaults for run file.cs. Defaults to false.
106+
--dnx-alias ALIAS Assign an alias on first usage which can be used instead of the full ref.
107+
--dnx-debug Launch the debugger before running.
108+
--dnx-force Force download, skipping ETag checking.
105109
```
106110

107111
> [!TIP]

src/Core/RemoteRunner.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ public class RemoteRunner(RemoteRef location, string toolName, Config? config =
99
{
1010
Config config = config ?? Config.Build(Config.GlobalLocation);
1111

12-
public async Task<int> RunAsync(string[] args, bool aot)
12+
public async Task<int> RunAsync(string[] args, bool aot, bool force = false)
1313
{
14-
var etag = config.GetString(toolName, location.ToString(), "etag");
15-
if (etag != null && Directory.Exists(location.TempPath))
14+
// Only use cached ETag if not forcing a fresh download
15+
if (!force)
1616
{
17-
if (etag.StartsWith("W/\"", StringComparison.OrdinalIgnoreCase) && !etag.EndsWith('"'))
18-
etag += '"';
17+
var etag = config.GetString(toolName, location.ToString(), "etag");
18+
if (etag != null && Directory.Exists(location.TempPath))
19+
{
20+
if (etag.StartsWith("W/\"", StringComparison.OrdinalIgnoreCase) && !etag.EndsWith('"'))
21+
etag += '"';
1922

20-
location = location with { ETag = etag };
21-
}
23+
location = location with { ETag = etag };
24+
}
2225

23-
if (config.TryGetString(toolName, location.ToString(), "uri", out var url) &&
24-
Uri.TryCreate(url, UriKind.Absolute, out var uri))
25-
location = location with { ResolvedUri = uri };
26+
if (config.TryGetString(toolName, location.ToString(), "uri", out var url) &&
27+
Uri.TryCreate(url, UriKind.Absolute, out var uri))
28+
location = location with { ResolvedUri = uri };
29+
}
2630

2731
if (DotnetMuxer.Path is null)
2832
{

src/gist/Program.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine;
2+
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34
using System.Text;
45
using Devlooped;
@@ -11,20 +12,36 @@
1112

1213
// Default PublishAot=false since it severely limits the code that can run (i.e. no reflection, STJ even)
1314
var aot = false;
14-
if (args.Any(x => x == "--aot"))
15+
if (args.Any(x => x is "--aot" or "--dnx-aot"))
1516
{
1617
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")];
1835
}
1936

2037
var config = Config.Build(Config.GlobalLocation);
2138
if (args.Length > 0 && config.GetString("runfile", args[0]) is string aliased)
2239
args = [aliased, .. args[1..]];
2340

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);
2845
if (alias != null)
2946
args = [.. parsed.UnmatchedTokens];
3047

@@ -38,7 +55,7 @@
3855
AnsiConsole.MarkupLine(
3956
$"""
4057
Usage:
41-
[grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [grey][[--alias ALIAS]][/] [bold]<gistRef>[/] [grey italic][[<appArgs>...]][/]
58+
[grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[OPTIONS]][/] [bold]<gistRef>[/] [grey italic][[<appArgs>...]][/]
4259
4360
Arguments:
4461
[bold]<GIST_REF>[/] Reference to gist file to run, with format [yellow]owner/gist[[@commit]][[:path]][/]
@@ -49,20 +66,26 @@
4966
* kzu/0ac826dc7de666546aaedd38e5965381 (tip commit and program.cs or first .cs file)
5067
* kzu/0ac826dc7de666546aaedd38e5965381@d8079cf:run.cs (explicit commit and file path)
5168
52-
If --alias was used in a previous run, the alias can be used instead of the full ref.
69+
If --dnx-alias was used in a previous run, the alias can be used instead of the full ref.
5370
5471
[bold]<appArgs>[/] Arguments passed to the C# program that is being run.
5572
5673
Options:
57-
[bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
58-
[bold]--alias[/] ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
74+
[bold]--dnx-aot[/] Enable dotnet AOT defaults for run file.cs. Defaults to false.
75+
[bold]--dnx-alias[/] ALIAS Assign an alias on first usage which can be used instead of the full ref.
76+
[bold]--dnx-debug[/] Launch the debugger before running.
77+
[bold]--dnx-force[/] Force download, skipping ETag checking.
5978
""");
6079
return;
6180
}
6281

6382
if (alias != null)
6483
config = config.SetString("runfile", alias, location.ToString());
6584

85+
// Launch debugger if --dnx-debug was specified
86+
if (debug)
87+
Debugger.Launch();
88+
6689
// Create the dispatcher on the main thread. This is required
6790
// for some platform UI services such as macOS that mandates
6891
// all controls are created/accessed on the initial thread
@@ -73,7 +96,7 @@
7396
// to process the dispatcher's job queue.
7497
var main = Task
7598
.Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName, config)
76-
.RunAsync(args[1..], aot))
99+
.RunAsync(args[1..], aot, force))
77100
.ContinueWith(t =>
78101
{
79102
Dispatcher.MainThread.Shutdown();

src/gist/readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Run C# code programs from GitHub gists.
88

99
```
10-
Usage: [dnx] gist [--aot] [--alias ALIAS] <gistRef> [<appArgs>...]
10+
Usage: [dnx] gist [OPTIONS] <gistRef> [<appArgs>...]
1111
1212
Arguments:
1313
<GIST_REF> Reference to gist file to run, with format owner/gist[@commit][:path]
@@ -18,13 +18,15 @@ Arguments:
1818
* kzu/0ac826dc7de666546aaedd38e5965381 (tip commit and program.cs or first .cs file)
1919
* kzu/0ac826dc7de666546aaedd38e5965381@d8079cf:run.cs (explicit commit and file path)
2020
21-
Can be an alias previously set with --alias.
21+
Can be an alias previously set with --dnx-alias.
2222
2323
<appArgs> Arguments passed to the C# program that is being run.
2424
2525
Options:
26-
--aot (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
27-
--alias ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
26+
--dnx-aot Enable dotnet AOT defaults for run file.cs. Defaults to false.
27+
--dnx-alias ALIAS Assign an alias on first usage which can be used instead of the full ref.
28+
--dnx-debug Launch the debugger before running.
29+
--dnx-force Force download, skipping ETag checking.
2830
```
2931

3032
> [!TIP]

src/runfile/Program.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine;
2+
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34
using System.Text;
45
using Devlooped;
@@ -11,20 +12,36 @@
1112

1213
// Default PublishAot=false since it severely limits the code that can run (i.e. no reflection, STJ even)
1314
var aot = false;
14-
if (args.Any(x => x == "--aot"))
15+
if (args.Any(x => x is "--aot" or "--dnx-aot"))
1516
{
1617
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")];
1835
}
1936

2037
var config = Config.Build(Config.GlobalLocation);
2138
if (args.Length > 0 && config.GetString("runfile", args[0]) is string aliased)
2239
args = [aliased, .. args[1..]];
2340

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);
2845
if (alias != null)
2946
args = [.. parsed.UnmatchedTokens];
3047

@@ -33,7 +50,7 @@
3350
AnsiConsole.MarkupLine(
3451
$"""
3552
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>...]][/]
3754
3855
Arguments:
3956
[bold]<REPO_REF>[/] Reference to remote file to run, with format [yellow][[host/]]owner/repo[[@ref]][[:path]][/]
@@ -46,20 +63,26 @@
4663
* gitlab.com/kzu/sandbox@main:run.cs (all explicit parts)
4764
* kzu/sandbox (implied host github.com, ref and path defaults)
4865
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.
5067
5168
[bold]<appArgs>[/] Arguments passed to the C# program that is being run.
5269
5370
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.
5675
""");
5776
return;
5877
}
5978

6079
if (alias != null)
6180
config = config.SetString("runfile", alias, location.ToString());
6281

82+
// Launch debugger if --dnx-debug was specified
83+
if (debug)
84+
Debugger.Launch();
85+
6386
// Create the dispatcher on the main thread. This is required
6487
// for some platform UI services such as macOS that mandates
6588
// all controls are created/accessed on the initial thread
@@ -70,7 +93,7 @@
7093
// to process the dispatcher's job queue.
7194
var main = Task
7295
.Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName, config)
73-
.RunAsync(args[1..], aot))
96+
.RunAsync(args[1..], aot, force))
7497
.ContinueWith(t =>
7598
{
7699
Dispatcher.MainThread.Shutdown();

src/runfile/readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Run C# code programs from git repos on GitHub, GitLab and Azure DevOps.
77

88
```
99
Usage:
10-
[dnx] runfile [--aot] [--alias ALIAS] <repoRef> [<appArgs>...]
10+
[dnx] runfile [OPTIONS] <repoRef> [<appArgs>...]
1111
1212
Arguments:
1313
<REPO_REF> Reference to remote file to run, with format [host/]owner/repo[@ref][:path]
@@ -20,13 +20,15 @@ Arguments:
2020
* gitlab.com/kzu/sandbox@main:run.cs (all explicit parts)
2121
* kzu/sandbox (implied host github.com, ref and path defaults)
2222
23-
Can be an alias previously set with --alias.
23+
Can be an alias previously set with --dnx-alias.
2424
2525
<appArgs> Arguments passed to the C# program that is being run.
2626
2727
Options:
28-
--aot (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
29-
--alias ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
28+
--dnx-aot Enable dotnet AOT defaults for run file.cs. Defaults to false.
29+
--dnx-alias ALIAS Assign an alias on first usage which can be used instead of the full ref.
30+
--dnx-debug Launch the debugger before running.
31+
--dnx-force Force download, skipping ETag checking.
3032
```
3133

3234
Example:

0 commit comments

Comments
 (0)