-
Notifications
You must be signed in to change notification settings - Fork 53
Update argument parsing and change a namespace name #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ | |
|
||
using System; | ||
using System.Threading.Tasks; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Runspaces; | ||
|
||
using Azure.Functions.PowerShell.Worker.Messaging; | ||
using CommandLine; | ||
using Microsoft.Azure.Functions.PowerShellWorker.Messaging; | ||
using Microsoft.Azure.Functions.PowerShellWorker.PowerShell.Host; | ||
using Microsoft.Azure.Functions.PowerShellWorker.Requests; | ||
using Microsoft.Azure.Functions.PowerShellWorker.Utility; | ||
|
@@ -29,12 +31,17 @@ static void InitPowerShell() | |
|
||
s_runspace = RunspaceFactory.CreateRunspace(host); | ||
s_runspace.Open(); | ||
s_ps = System.Management.Automation.PowerShell.Create(InitialSessionState.CreateDefault()); | ||
s_ps = System.Management.Automation.PowerShell.Create(); | ||
s_ps.Runspace = s_runspace; | ||
|
||
s_ps.AddScript("$PSHOME"); | ||
//s_ps.AddCommand("Set-ExecutionPolicy").AddParameter("ExecutionPolicy", ExecutionPolicy.Unrestricted).AddParameter("Scope", ExecutionPolicyScope.Process); | ||
s_ps.Invoke<string>(); | ||
if (Platform.IsWindows) | ||
{ | ||
s_ps.AddCommand("Set-ExecutionPolicy") | ||
.AddParameter("ExecutionPolicy", "Unrestricted") | ||
.AddParameter("Scope", "Process") | ||
.Invoke(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I updated this in my PR. We can deal with the merge conflicts later. Yours is better anyway. |
||
s_ps.Commands.Clear(); | ||
} | ||
|
||
// Add HttpResponseContext namespace so users can reference | ||
// HttpResponseContext without needing to specify the full namespace | ||
|
@@ -44,21 +51,23 @@ static void InitPowerShell() | |
|
||
public async static Task Main(string[] args) | ||
{ | ||
StartupArguments startupArguments = StartupArguments.Parse(args); | ||
WorkerArguments arguments = null; | ||
Parser.Default.ParseArguments<WorkerArguments>(args) | ||
.WithParsed(ops => arguments = ops) | ||
.WithNotParsed(err => Environment.Exit(1)); | ||
|
||
// Initialize Rpc client, logger, and PowerShell | ||
s_client = new FunctionMessagingClient(startupArguments.Host, startupArguments.Port); | ||
s_client = new FunctionMessagingClient(arguments.Host, arguments.Port); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on this usage, I guess we can assume that the action call in WithParsed is synchronous. It's an interesting package. In the javascript world the callback pattern doesn't have that guarantee at all. |
||
s_logger = new RpcLogger(s_client); | ||
InitPowerShell(); | ||
|
||
// Send StartStream message | ||
var streamingMessage = new StreamingMessage() { | ||
RequestId = startupArguments.RequestId, | ||
StartStream = new StartStream() { WorkerId = startupArguments.WorkerId } | ||
RequestId = arguments.RequestId, | ||
StartStream = new StartStream() { WorkerId = arguments.WorkerId } | ||
}; | ||
|
||
await s_client.WriteAsync(streamingMessage); | ||
|
||
await ProcessEvent(); | ||
} | ||
|
||
|
@@ -105,4 +114,22 @@ static async Task ProcessEvent() | |
} | ||
} | ||
} | ||
} | ||
|
||
internal class WorkerArguments | ||
{ | ||
[Option("host", Required = true, HelpText = "IP Address used to connect to the Host via gRPC.")] | ||
public string Host { get; set; } | ||
|
||
[Option("port", Required = true, HelpText = "Port used to connect to the Host via gRPC.")] | ||
public int Port { get; set; } | ||
|
||
[Option("workerId", Required = true, HelpText = "Worker ID assigned to this language worker.")] | ||
public string WorkerId { get; set; } | ||
|
||
[Option("requestId", Required = true, HelpText = "Request ID used for gRPC communication with the Host.")] | ||
public string RequestId { get; set; } | ||
|
||
[Option("grpcMaxMessageLength", Required = true, HelpText = "gRPC Maximum message size.")] | ||
public int MaxMessageLength { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for doing this. I'm not totally sold that this is the best namespace name but at least we're consistent.