Skip to content

Commit

Permalink
Add 'noninteractive' command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
balasub committed Nov 6, 2024
1 parent 348a805 commit abc77ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Src/CommandLine/CommandInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ private enum WatchLevelKind { Off, On, Prompt };
public const string ExitCommand = "exit";
public const string ExitShortCommand = "x";

public const string NonInteractiveCommand = "noninteractive";

private const string BusyMsg = "Busy; cancel or wait until operation completes";
private const string UnkCmdMsg = "Unknown command '{0}'";
private const string UnkSwitchMsg = "Unknown switch '{0}'";
Expand Down Expand Up @@ -373,9 +375,10 @@ public void Dispose()
{
}

internal bool DoOptions(out bool isExit)
internal bool DoOptions(out bool isExit, out bool isNonInteractive)
{
isExit = false;
isNonInteractive = false;

if (!GetCommandLock())
{
Expand Down Expand Up @@ -410,6 +413,11 @@ internal bool DoOptions(out bool isExit)
isExit = true;
break;
}
else if (opt.Item1 == NonInteractiveCommand)
{
isNonInteractive = true;
break;
}
else if (opt.Item2.Count == 0)
{
sink.WriteMessageLine(opt.Item1);
Expand Down
7 changes: 4 additions & 3 deletions Src/CommandLine/CommandLineProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ public static void Main(string[] args)

//// If errors occured while parsing switches
//// then treat this an exit condition.
bool isExit;
ci.DoOptions(out isExit);
bool isExit, isNonInteractive;
ci.DoOptions(out isExit, out isNonInteractive);
if (isExit || sink.PrintedError)
{
Environment.ExitCode = sink.PrintedError ? 1 : 0;
return;
}

if (OperatingSystem.IsMacOS() &&
chooser.Interactive)
chooser.Interactive &&
!isNonInteractive)
{
InteractivePrompt.Run(ci);
Environment.ExitCode = sink.PrintedError ? 1 : 0;
Expand Down

0 comments on commit abc77ff

Please sign in to comment.