Skip to content

Commit

Permalink
Add a --no-interactive switch to func run command. Closes #93
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed committed May 24, 2017
1 parent c97f373 commit 6e3aad0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/Azure.Functions.Cli/Actions/LocalActions/RunFunctionAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RunFunctionAction : BaseAction
public string Content { get; set; }
public string FileName { get; set; }
public bool Debug { get; set; }
public bool NoInteractive { get; set; }

public RunFunctionAction(IFunctionsLocalServer scriptServer)
{
Expand All @@ -56,6 +57,11 @@ public override ICommandLineParserResult ParseArgs(string[] args)
.WithDescription("Attach a debugger to the host process before running the function")
.Callback(d => Debug = d);

Parser
.Setup<bool>("no-interactive")
.WithDescription("Don't prompt or expect any stdin.")
.Callback(f => NoInteractive = f);

if (args.Any())
{
FunctionName = args
Expand All @@ -76,7 +82,7 @@ public override ICommandLineParserResult ParseArgs(string[] args)

public override async Task RunAsync()
{
using (var client = await _scriptServer.ConnectAsync(Timeout))
using (var client = await _scriptServer.ConnectAsync(Timeout, NoInteractive))
{
var hostStatusResponse = await client.GetAsync("admin/host/status");
var functionStatusResponse = await client.GetAsync($"admin/functions/{FunctionName}/status");
Expand Down Expand Up @@ -152,10 +158,14 @@ public override async Task RunAsync()
.WriteLine(ErrorColor("Unable to configure node debugger. Check your launch.json."));
return;
}
else if (!NoInteractive)
{
ColoredConsole.WriteLine("launch.json configured.");
}
else
{
ColoredConsole
.Write("launch.json configured. Setup your break points, launch debugger (F5), and press any key to continue...");
.Write("launch.json configured. Setup your break points, launch debugger (F5), and press any key to continue...");
Console.ReadKey();
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Azure.Functions.Cli/FunctionsLocalServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public FunctionsLocalServer(IProcessManager processManager, ISettings settings,
_secretsManager = secretesManager;
}

public async Task<HttpClient> ConnectAsync(TimeSpan timeout)
public async Task<HttpClient> ConnectAsync(TimeSpan timeout, bool noInteractive)
{
var server = await DiscoverServer();
var server = await DiscoverServer(noInteractive);
var startTime = DateTime.UtcNow;
while (!await server.IsServerRunningAsync() &&
startTime.Add(timeout) > DateTime.UtcNow)
Expand All @@ -43,7 +43,7 @@ public async Task<HttpClient> ConnectAsync(TimeSpan timeout)
return new HttpClient() { BaseAddress = server, Timeout = timeout };
}

private async Task<Uri> DiscoverServer()
private async Task<Uri> DiscoverServer(bool noInteractive)
{
var hostSettings = _secretsManager.GetHostStartSettings();
if (hostSettings.LocalHttpPort != default(int))
Expand All @@ -55,17 +55,17 @@ private async Task<Uri> DiscoverServer()
}
}

return await RecursiveDiscoverServer(0);
return await RecursiveDiscoverServer(0, noInteractive);
}

private async Task<Uri> RecursiveDiscoverServer(int iteration = 0)
private async Task<Uri> RecursiveDiscoverServer(int iteration, bool noInteractive)
{
var server = new Uri($"http://localhost:{Port + iteration}");

if (!await server.IsServerRunningAsync())
{
// create the server
if (_settings.DisplayLaunchingRunServerWarning)
if (_settings.DisplayLaunchingRunServerWarning && !noInteractive)
{
ColoredConsole
.WriteLine()
Expand Down Expand Up @@ -107,7 +107,7 @@ private async Task<Uri> RecursiveDiscoverServer(int iteration = 0)
}
else
{
return await RecursiveDiscoverServer(iteration + 1);
return await RecursiveDiscoverServer(iteration + 1, noInteractive);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Azure.Functions.Cli.Interfaces
{
internal interface IFunctionsLocalServer
{
Task<HttpClient> ConnectAsync(TimeSpan timeout);
Task<HttpClient> ConnectAsync(TimeSpan timeout, bool noInteractive);
}
}

0 comments on commit 6e3aad0

Please sign in to comment.