New3Command.Run
internal TemplateInvoker( IEngineEnvironmentSettings environment, ITelemetryLogger telemetryLogger, Func <string> inputGetter, NewCommandCallbacks callbacks) { _environmentSettings = environment; _telemetryLogger = telemetryLogger; _inputGetter = inputGetter; _callbacks = callbacks; _templateCreator = new TemplateCreator(_environmentSettings); _postActionDispatcher = new PostActionDispatcher(_environmentSettings, _callbacks, _inputGetter); }
public static System.CommandLine.Command GetCommand() { var getLogger = (ParseResult parseResult) => { var sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName); // senderCount: 0 to disable sender. // When senders in different process running at the same // time they will read from the same global queue and cause // sending duplicated events. Disable sender to reduce it. var telemetry = new Microsoft.DotNet.Cli.Telemetry.Telemetry(new FirstTimeUseNoticeSentinel(), sessionId, senderCount: 0); var logger = new TelemetryLogger(null); if (telemetry.Enabled) { logger = new TelemetryLogger((name, props, measures) => { if (telemetry.Enabled) { telemetry.TrackEvent($"template/{name}", props, measures); } }); } return(logger); }; var callbacks = new Microsoft.TemplateEngine.Cli.NewCommandCallbacks() { RestoreProject = RestoreProject }; var getEngineHost = (ParseResult parseResult) => { var disableSdkTemplates = parseResult.GetValueForOption(_disableSdkTemplates); return(CreateHost(disableSdkTemplates)); }; var command = Microsoft.TemplateEngine.Cli.NewCommandFactory.Create(CommandName, getEngineHost, getLogger, callbacks); // adding this option lets us look for its bound value during binding in a typed way command.AddGlobalOption(_disableSdkTemplates); return(command); }
/// <summary> /// Creates the instance. /// </summary> /// <param name="environment">template engine environment settings.</param> /// <param name="callbacks">callbacks that can be used for post actions.</param> /// <param name="inputGetter">the predicate to get user input whether to run the post action.</param> internal PostActionDispatcher(IEngineEnvironmentSettings environment, NewCommandCallbacks callbacks, Func <string> inputGetter) { _environment = environment ?? throw new ArgumentNullException(nameof(environment)); _callbacks = callbacks ?? throw new ArgumentNullException(nameof(callbacks)); _inputGetter = inputGetter ?? throw new ArgumentNullException(nameof(inputGetter)); }
public static Command Create(string commandName, Func <ParseResult, ITemplateEngineHost> hostBuilder, Func <ParseResult, ITelemetryLogger> telemetryLoggerBuilder, NewCommandCallbacks callbacks) { if (string.IsNullOrWhiteSpace(commandName)) { throw new ArgumentException($"'{nameof(commandName)}' cannot be null or whitespace.", nameof(commandName)); } _ = hostBuilder ?? throw new ArgumentNullException(nameof(hostBuilder)); _ = telemetryLoggerBuilder ?? throw new ArgumentNullException(nameof(telemetryLoggerBuilder)); _ = callbacks ?? throw new ArgumentNullException(nameof(callbacks)); return(new NewCommand(commandName, hostBuilder, telemetryLoggerBuilder, callbacks)); }