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
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ with smart up-to-date checks of every C# file used to build the app (including
Every successful `go` / `go dev` invocation records the entry point (local full path or
remote ref) in a shared history file next to the cache root (`dotnet/go/go.toml`).

With at least one history entry, running with **no arguments** opens an interactive
picker (searchable, ordered by use count then recency). After you pick an entry you
can optionally type app arguments (quoted groups supported). With an empty history,
`dnx go` with no args shows help instead.
With at least one history entry, running with **no arguments** in an interactive
terminal opens a searchable picker (ordered by use count then recency). After you
pick an entry you can optionally type app arguments (quoted groups supported).
With an empty history, or when stdin is redirected / non-interactive (CI, pipes),
`dnx go` with no args shows help instead of erroring.

Local paths that no longer exist are dropped from the picker; remote refs stay listed
even when their download bundle is gone (the next run re-downloads as usual).
Expand Down
31 changes: 25 additions & 6 deletions src/go/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
app.Add<SkillCommands>();

var prepared = GoArgs.PrepareArgs(args);
// Zero-arg with no prior runs: show help (same as -h/--help/-?). With history, default command opens the MRU picker.
if (prepared.Length == 0 && RunHistory.List().Count == 0)
// Zero-arg: help when history is empty or the console cannot prompt (redirected stdin / non-interactive).
// With history + an interactive terminal, the default command opens the MRU picker.
if (prepared.Length == 0 && (RunHistory.List().Count == 0 || !CanPromptInteractively()))
prepared = ["--help"];

await app.RunAsync(prepared);
Expand Down Expand Up @@ -235,15 +236,34 @@ static int CleanArtifacts(string? input, bool all, string? missingInputMessage)
return AppCleaner.Clean(pdir, stmp, cs);
}

/// <summary>
/// True when stdin is a real terminal that can drive Spectre prompts.
/// Redirected/piped input falls through to help instead of the MRU picker.
/// </summary>
static bool CanPromptInteractively()
{
try
{
if (Console.IsInputRedirected)
return false;

return AnsiConsole.Profile.Capabilities.Interactive;
}
catch
{
return false;
}
}

/// <summary>
/// Interactive MRU picker over go.toml history, then optional app-args prompt.
/// Returns null on empty history, cancel, or non-interactive console.
/// Returns null on empty history, cancel, or if prompts cannot run (caller shows help for zero-arg).
/// </summary>
static string? TryPickFromHistory(out string[] appArgs)
{
appArgs = [];
var history = RunHistory.List();
if (history.Count == 0)
if (history.Count == 0 || !CanPromptInteractively())
return null;

try
Expand All @@ -267,8 +287,7 @@ static int CleanArtifacts(string? input, bool all, string? missingInputMessage)
}
catch (Exception)
{
// Spectre throws when stdin is redirected / no interactive terminal.
ConsoleApp.LogError("Interactive selection requires a terminal.");
// Cancelled prompt or unexpected non-interactive environment — no error noise.
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/go/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Usage: [command] [arguments...] [options...] [-h|--help] [--version]
Runs a file-based .NET app from a .cs entrypoint.

Arguments:
[0] <string?> Path to an existing .cs file or remote ref (owner/repo[@ref][:path]). When omitted, selects from previous runs (MRU) then prompts for optional app args.
[0] <string?> Path to an existing .cs file or remote ref (owner/repo[@ref][:path]). When omitted in an interactive terminal, selects from previous runs (MRU) then prompts for optional app args; otherwise shows help.
[1] <string[]> Arguments to pass to the app.

Options:
Expand Down
Loading