Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Run C# code programs from git repos on GitHub, GitLab and Azure DevOps.

```
Usage:
[dnx] runcs <repoRef> [<appArgs>...]
[dnx] runcs [--aot] [--alias ALIAS] <repoRef> [<appArgs>...]

Arguments:
<REPO_REF> Reference to remote file to run, with format [host/]owner/repo[@ref][:path]
Expand All @@ -25,7 +25,13 @@ Arguments:
* gitlab.com/kzu/sandbox@main:run.cs (all explicit parts)
* kzu/sandbox (implied host github.com, ref and path defaults)

Can be an alias previously set with --alias.

<appArgs> Arguments passed to the C# program that is being run.

Options:
--aot (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
--alias ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
```

Example:
Expand All @@ -50,16 +56,24 @@ The last download etag is used to avoid downloading on each run.
Run C# code programs from GitHub gists.

```
Usage: [dnx] gist <gistRef> [<appArgs>...]
Usage: [dnx] gist [--aot] [--alias ALIAS] <gistRef> [<appArgs>...]

Arguments:
<GIST_REF> Reference to gist file to run, with format owner/gist[@commit][:path]
@commit optional gist commit (default: default branch)
@commit optional gist commit (default: latest)
:path optional path to file in gist (default: program.cs or first .cs file)

Examples:
* kzu/0ac826dc7de666546aaedd38e5965381 (tip commit and program.cs or first .cs file)
* kzu/0ac826dc7de666546aaedd38e5965381@d8079cf:run.cs (explicit commit and file path)

<appArgs> Arguments passed to the C# program gist that is being run.
Can be an alias previously set with --alias.

<appArgs> Arguments passed to the C# program that is being run.

Options:
--aot (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
--alias ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
```

> [!TIP]
Expand Down
6 changes: 4 additions & 2 deletions src/Core/RemoteRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

namespace Devlooped;

public class RemoteRunner(RemoteRef location, string toolName)
public class RemoteRunner(RemoteRef location, string toolName, Config? config = null)
{
Config config = config ?? Config.Build(Config.GlobalLocation);

public async Task<int> RunAsync(string[] args, bool aot)
{
var config = Config.Build(Config.GlobalLocation);
var etag = config.GetString(toolName, location.ToString(), "etag");
if (etag != null && Directory.Exists(location.TempPath))
{
Expand All @@ -18,6 +19,7 @@ public async Task<int> RunAsync(string[] args, bool aot)

location = location with { ETag = etag };
}

if (config.TryGetString(toolName, location.ToString(), "uri", out var url) &&
Uri.TryCreate(url, UriKind.Absolute, out var uri))
location = location with { ResolvedUri = uri };
Expand Down
29 changes: 24 additions & 5 deletions src/gist/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Runtime.InteropServices;
using System.CommandLine;
using System.Runtime.InteropServices;
using System.Text;
using Devlooped;
using DotNetConfig;
using GitCredentialManager.UI;
using Spectre.Console;

Expand All @@ -15,12 +17,23 @@
args = [.. args.Where(x => x != "--aot")];
}

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

// Set alias and remove from args if present
var option = new Option<string?>("--alias");
var parsed = new RootCommand() { Options = { option } }.Parse(args);
var alias = parsed.GetValue(option);
if (alias != null)
args = [.. parsed.UnmatchedTokens];

if (args.Length == 0 || !RemoteRef.TryParse("gist.github.com/" + args[0], out var location))
{
AnsiConsole.MarkupLine(
$"""
Usage:
[grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [bold]<gistRef>[/] [grey italic][[<appArgs>...]][/]
[grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [grey][[--alias ALIAS]][/] [bold]<gistRef>[/] [grey italic][[<appArgs>...]][/]

Arguments:
[bold]<GIST_REF>[/] Reference to gist file to run, with format [yellow]owner/gist[[@commit]][[:path]][/]
Expand All @@ -30,15 +43,21 @@
Examples:
* kzu/0ac826dc7de666546aaedd38e5965381 (tip commit and program.cs or first .cs file)
* kzu/0ac826dc7de666546aaedd38e5965381@d8079cf:run.cs (explicit commit and file path)


Can be an alias previously set with --alias.

[bold]<appArgs>[/] Arguments passed to the C# program that is being run.

Options:
[bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
[bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
[bold]--alias[/] ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
""");
return;
}

if (alias != null)
config = config.SetString("runcs", alias, location.ToString());

// Create the dispatcher on the main thread. This is required
// for some platform UI services such as macOS that mandates
// all controls are created/accessed on the initial thread
Expand All @@ -48,7 +67,7 @@
// Run AppMain in a new thread and keep the main thread free
// to process the dispatcher's job queue.
var main = Task
.Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName)
.Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName, config)
.RunAsync(args[1..], aot))
.ContinueWith(t =>
{
Expand Down
3 changes: 3 additions & 0 deletions src/gist/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"profiles": {
"help": {
"commandName": "Project",
},
"gist": {
"commandName": "Project",
"commandLineArgs": "kzu/0ac826dc7de666546aaedd38e5965381"
Expand Down
3 changes: 2 additions & 1 deletion src/gist/gist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageTags>dotnet dotnet-tool</PackageTags>

<Description>Run gists directly using: dnx gist owner/gist[:path]</Description>
<Description>Run C# code gists directly using: dnx gist owner/gist[:path]</Description>
</PropertyGroup>

<ItemGroup>
Expand All @@ -21,6 +21,7 @@
<PackageReference Include="Avalonia" Version="11.3.4" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.4" />
<PackageReference Include="git-credential-manager" Version="2.6.1" IncludeAssets="tools" GeneratePathProperty="true" />
<PackageReference Include="System.CommandLine" Version="2.0.0-rc.1.25451.107" />
</ItemGroup>

<ItemGroup Condition="'$(Pkggit-credential-manager)' != ''">
Expand Down
27 changes: 23 additions & 4 deletions src/runcs/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Runtime.InteropServices;
using System.CommandLine;
using System.Runtime.InteropServices;
using System.Text;
using Devlooped;
using DotNetConfig;
using GitCredentialManager.UI;
using Spectre.Console;

Expand All @@ -15,12 +17,23 @@
args = [.. args.Where(x => x != "--aot")];
}

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

// Set alias and remove from args if present
var option = new Option<string?>("--alias");
var parsed = new RootCommand() { Options = { option } }.Parse(args);
var alias = parsed.GetValue(option);
if (alias != null)
args = [.. parsed.UnmatchedTokens];

if (args.Length == 0 || !RemoteRef.TryParse(args[0], out var location))
{
AnsiConsole.MarkupLine(
$"""
Usage:
[grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [bold]<repoRef>[/] [grey italic][[<appArgs>...]][/]
[grey][[dnx]][/] [lime]{ThisAssembly.Project.ToolCommandName}[/] [grey][[--aot]][/] [grey][[--alias ALIAS]][/] [bold]<repoRef>[/] [grey italic][[<appArgs>...]][/]

Arguments:
[bold]<REPO_REF>[/] Reference to remote file to run, with format [yellow][[host/]]owner/repo[[@ref]][[:path]][/]
Expand All @@ -33,14 +46,20 @@
* gitlab.com/kzu/sandbox@main:run.cs (all explicit parts)
* kzu/sandbox (implied host github.com, ref and path defaults)

Can be an alias previously set with --alias.

[bold]<appArgs>[/] Arguments passed to the C# program that is being run.

Options:
[bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
[bold]--aot[/] (optional) Enable dotnet AOT defaults for run file.cs. Defaults to false.
[bold]--alias[/] ALIAS (optional) Assign an alias on first usage which can be used instead of the full ref.
""");
return;
}

if (alias != null)
config = config.SetString("runcs", alias, location.ToString());

// Create the dispatcher on the main thread. This is required
// for some platform UI services such as macOS that mandates
// all controls are created/accessed on the initial thread
Expand All @@ -50,7 +69,7 @@
// Run AppMain in a new thread and keep the main thread free
// to process the dispatcher's job queue.
var main = Task
.Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName)
.Run(() => new RemoteRunner(location, ThisAssembly.Project.ToolCommandName, config)
.RunAsync(args[1..], aot))
.ContinueWith(t =>
{
Expand Down
8 changes: 8 additions & 0 deletions src/runcs/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"profiles": {
"help": {
"commandName": "Project"
},
"args": {
"commandName": "Project",
"commandLineArgs": "--aot kzu/runcs@v1 dotnet rocks"
Expand All @@ -23,6 +26,11 @@
"vault2secrets": {
"commandName": "Project",
"commandLineArgs": "kzu/run:vault2secrets.cs"
},
"clean": {
"commandName": "Project",
"commandLineArgs": "clean",
"workingDirectory": "C:\\Code\\WhatsApp"
}
}
}
1 change: 1 addition & 0 deletions src/runcs/runcs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
<PackageReference Include="Spectre.Console" Version="0.50.0" />
<PackageReference Include="ThisAssembly" Version="2.0.14" PrivateAssets="all"/>
<PackageReference Include="System.CommandLine" Version="2.0.0-rc.1.25451.107" />
</ItemGroup>

<ItemGroup Condition="'$(Pkggit-credential-manager)' != ''">
Expand Down