/// <summary> /// Creates an instance of <see cref="CliApplication"/> or <see cref="InteractiveCliApplication"/> using configured parameters. /// Default values are used in place of parameters that were not specified. /// </summary> public CliApplication Build() { if (_cliApplicationBuilt) { throw new InvalidOperationException("Build can only be called once."); } _cliApplicationBuilt = true; // Set default values _title ??= AssemblyExtensions.TryGetDefaultTitle() ?? "App"; _executableName ??= AssemblyExtensions.TryGetDefaultExecutableName() ?? "app"; _versionText ??= AssemblyExtensions.TryGetDefaultVersionText() ?? "v1.0"; _console ??= new SystemConsole(); _exceptionHandler ??= new DefaultExceptionHandler(); _userDefinedShortcuts ??= new HashSet <ShortcutDefinition>(); // Format startup message if (_startupMessage != null) { _startupMessage = Regex.Replace(_startupMessage, @"{(?<x>[^}]+)}", match => { string value = match.Groups["x"].Value; return(value.ToLower() switch { "title" => _title, "executable" => _executableName, "version" => _versionText, "description" => _description ?? string.Empty, _ => string.Concat("{", value, "}") }); });