Skip to content

Commit aa73a4d

Browse files
committed
Fall back to help when MRU picker cannot run interactively
Zero-arg go with history still needs a real terminal for the Spectre picker. Redirected stdin or non-interactive consoles now take the same path as empty history and show help, instead of logging an error and exiting 1. Document the behavior in the readme and help text.
1 parent 8347330 commit aa73a4d

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

readme.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ with smart up-to-date checks of every C# file used to build the app (including
4545
Every successful `go` / `go dev` invocation records the entry point (local full path or
4646
remote ref) in a shared history file next to the cache root (`dotnet/go/go.toml`).
4747

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

5354
Local paths that no longer exist are dropped from the picker; remote refs stay listed
5455
even when their download bundle is gone (the next run re-downloads as usual).

src/go/Program.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
app.Add<SkillCommands>();
1717

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

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

239+
/// <summary>
240+
/// True when stdin is a real terminal that can drive Spectre prompts.
241+
/// Redirected/piped input falls through to help instead of the MRU picker.
242+
/// </summary>
243+
static bool CanPromptInteractively()
244+
{
245+
try
246+
{
247+
if (Console.IsInputRedirected)
248+
return false;
249+
250+
return AnsiConsole.Profile.Capabilities.Interactive;
251+
}
252+
catch
253+
{
254+
return false;
255+
}
256+
}
257+
238258
/// <summary>
239259
/// Interactive MRU picker over go.toml history, then optional app-args prompt.
240-
/// Returns null on empty history, cancel, or non-interactive console.
260+
/// Returns null on empty history, cancel, or if prompts cannot run (caller shows help for zero-arg).
241261
/// </summary>
242262
static string? TryPickFromHistory(out string[] appArgs)
243263
{
244264
appArgs = [];
245265
var history = RunHistory.List();
246-
if (history.Count == 0)
266+
if (history.Count == 0 || !CanPromptInteractively())
247267
return null;
248268

249269
try
@@ -267,8 +287,7 @@ static int CleanArtifacts(string? input, bool all, string? missingInputMessage)
267287
}
268288
catch (Exception)
269289
{
270-
// Spectre throws when stdin is redirected / no interactive terminal.
271-
ConsoleApp.LogError("Interactive selection requires a terminal.");
290+
// Cancelled prompt or unexpected non-interactive environment — no error noise.
272291
return null;
273292
}
274293
}

src/go/help.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Usage: [command] [arguments...] [options...] [-h|--help] [--version]
44
Runs a file-based .NET app from a .cs entrypoint.
55

66
Arguments:
7-
[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.
7+
[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.
88
[1] <string[]> Arguments to pass to the app.
99

1010
Options:

0 commit comments

Comments
 (0)