protected override object CreateModel(ActionStatement action) { if (action.PositionalArguments?.Count != 1) { return(null); } var scriptName = LooselyQualifiedName.Parse(action.PositionalArguments[0]); var info = PowerShellScriptInfo.TryLoadAsync(scriptName).GetAwaiter().GetResult(); if (info == null) { return(null); } return(new PSCallOperationModel { ScriptName = scriptName.ToString(), Arguments = info.Parameters.Select(p => new Argument { DefaultValue = p.DefaultValue, Description = p.Description, IsBooleanOrSwitch = p.IsBooleanOrSwitch, IsOutput = p.IsOutput, Name = p.Name, Value = p.IsOutput ? action.OutArguments.GetValueOrDefault(p.Name)?.ToString() : action.Arguments.GetValueOrDefault(p.Name) }) }); }
protected override ExtendedRichDescription GetDescription(IOperationConfiguration config) { if (string.IsNullOrWhiteSpace(config.DefaultArgument)) { return(new ExtendedRichDescription(new RichDescription("PSVerify {error parsing statement}"))); } var defaultArg = config.DefaultArgument; var longDesc = new RichDescription(); bool longDescInclused = false; var scriptName = LooselyQualifiedName.TryParse(defaultArg); if (scriptName != null) { var info = PowerShellScriptInfo.TryLoad(scriptName); if (!string.IsNullOrEmpty(info?.Description)) { longDesc.AppendContent(info.Description); longDescInclused = true; } var listParams = new List <string>(); foreach (var prop in config.NamedArguments) { listParams.Add($"{prop.Key}: {prop.Value}"); } foreach (var prop in config.OutArguments) { listParams.Add($"{prop.Key} => {prop.Value}"); } if (listParams.Count > 0) { if (longDescInclused) { longDesc.AppendContent(" - "); } longDesc.AppendContent(new ListHilite(listParams)); longDescInclused = true; } } if (!longDescInclused) { longDesc.AppendContent("with no parameters"); } return(new ExtendedRichDescription( new RichDescription("PSVerify ", new Hilite(defaultArg)), longDesc )); }
public override ISimpleControl CreateView(ActionStatement action) { if (action.PositionalArguments?.Count != 1) { return(new LiteralHtml("Cannot edit this statement; the target script name is not present.")); } var scriptName = LooselyQualifiedName.Parse(action.PositionalArguments[0]); var info = PowerShellScriptInfo.TryLoadAsync(scriptName).GetAwaiter().GetResult(); if (info == null) { return(new LiteralHtml("Cannot edit this statement; script metatdata could not be parsed.")); } var argumentName = new KoElement(KoBind.text(nameof(Argument.Name))); var argumentDesc = new KoElement( KoBind.text(nameof(Argument.Description)) ); var field = new SlimFormField(new LiteralHtml(argumentName.ToString())); field.HelpText = new LiteralHtml(argumentDesc.ToString()); field.Controls.Add( new Element("input", new KoBindAttribute("planargvalue", nameof(Argument.Value))) { Attributes = { ["type"] = "text" } }); return(new SimpleVirtualCompositeControl( new SlimFormField("Script name:", info.Name ?? scriptName.ToString()), new Div( new KoElement( KoBind.@foreach(nameof(PSCallOperationModel.Arguments)), field ) ) { Class = "argument-container" }, new SlimFormField( "Parameters:", KoBind.visible($"{nameof(PSCallOperationModel.Arguments)}().length == 0"), "This script does not have any input or output parameters." ) )); }
public CallScriptInfo TryLoad(string name, object loadContext) { var scriptName = LooselyQualifiedName.Parse(name); var info = PowerShellScriptInfo.TryLoad(scriptName, loadContext); if (info == null) { return(null); } return(new CallScriptInfo( scriptName.ToString(), info.Parameters.Select(p => new CallScriptArgument { DefaultValue = p.DefaultValue, Description = p.Description, IsBooleanOrSwitch = p.IsBooleanOrSwitch, IsOutput = p.IsOutput, Name = p.Name }) )); }