public static async Task ResponseFileAsync(RunnerArgs args) { string[] responseFiles = args.Options["-f", "--file"]?.Values ?? Array.Empty <string>(); string command = args.Options["-c", "--command"]?.Value; if (responseFiles.Length == 0) { responseFiles = GetDefaultFiles(); if (responseFiles.Length == 0) { throw new RunnerException("Please specify at least one response file with -f|--file or create a default '<command>.cli' in the current directory."); } else if (responseFiles.Length > 1) { throw new RunnerException("Multiple default '<command>.cli' files found. Please specify the right one with the -c|--command argument."); } } string[] prefixedFiles = responseFiles.Select(f => f.StartsWith('@') ? f : '@' + f).ToArray(); string[] argumentList = ResponseFile.ExpandStrings(prefixedFiles).SelectMany(ToolOptions.ToArgumentList).SkipWhile(s => s == "cli").ToArray(); if (command != null && command != "cli") { argumentList = new[] { command } }
public async static Task SqlAsync(RunnerArgs args, IConnectionFactory factory) { if (factory == null) { throw new RunnerException("Invalid factory object."); } if (string.IsNullOrWhiteSpace(args.Connection)) { throw new RunnerException("Please specify a connection string using the -c|--connection argument."); } string[] inputs = args.Options["-s", "--sql"]?.Values ?? Array.Empty <string>(); if (inputs.Length == 0) { throw new RunnerException("Please specify at least one SQL input with the -s|--sql argument."); } using (DbConnection connection = await GetOpenConnectionAsync(args, factory)) { foreach (ResponseFile responseFile in inputs.Select(ResponseFile.Parse)) { if (responseFile.IsPath) { DotNetJerryHost.WriteLine($"Executing '@{Path.GetFileName(responseFile.InputPath)}'...", ConsoleColor.Yellow); if (!File.Exists(responseFile.FullPath)) { DotNetJerryHost.WriteLine($"Skipped. File not found.", ConsoleColor.Yellow); continue; } } else if (!responseFile.Ignore) { DotNetJerryHost.WriteLine($"Executing '{responseFile.Value}'...", ConsoleColor.Yellow); } using (DbCommand command = connection.CreateCommand()) { command.CommandText = string.Join(Environment.NewLine, ResponseFile.ExpandStrings(responseFile)); if (!string.IsNullOrWhiteSpace(command.CommandText)) { int affectedRows = await command.ExecuteNonQueryAsync(); string rowsMoniker = affectedRows + " " + (affectedRows == 1 ? "row" : "rows"); DotNetJerryHost.WriteLine($"OK. {rowsMoniker} affected.", ConsoleColor.Green); } else { DotNetJerryHost.WriteLine($"Skipped. SQL text is empty.", ConsoleColor.Yellow); } } } } }
private static IEnumerable <ToolOption> ParseAndYield(string[] args, ResponseSettings settings) { bool isDefault = true; List <string> newArgs = new List <string>(); foreach (string argument in args) { if (ResponseFile.HasPathSyntax(argument, out _)) { newArgs.AddRange(ResponseFile.ExpandStrings(argument, settings).SelectMany(ToArgumentList)); } else { newArgs.Add(argument); } } for (int i = 0; i < newArgs.Count; i++) { if (IsOption(newArgs[i])) { ToolOption option = CreateOption(newArgs[i]); if (option != null) { option.Values = newArgs.Skip(i + 1).TakeWhile(s => !IsOption(s)).ToArray(); i += option.Values.Length; option.Values = option.Values.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); } isDefault = false; yield return(option); } else if (isDefault) { ToolOption option = new ToolOption() { Name = "", ShortName = "", Values = newArgs.Skip(i).TakeWhile(s => !IsOption(s)).ToArray() }; i += option.Values.Length - 1; option.Values = option.Values.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); isDefault = false; yield return(option); } } }
public static ToolOptions ParseResponseFile(string input) { if (string.IsNullOrWhiteSpace(input)) { throw new ArgumentException("Value cannot be empty.", nameof(input)); } string[] args = ResponseFile.ExpandStrings(input).SelectMany(ToArgumentList).ToArray(); return(Parse(args)); }
public static void Transpile(RunnerArgs args) { string projectDirectory = args.Options["-p", "--project"]?.Value ?? Environment.CurrentDirectory; string rootNamespace = args.Options["-ns", "--namespace"]?.Value; string sourcePath = Path.GetDirectoryName(typeof(DotNetJerryHost).Assembly.Location); string skeletonPath = Path.Combine(sourcePath, "skeleton.jerry"); string outputDirectory = args.Options["-o", "--output"]?.Value; if (!Directory.Exists(projectDirectory)) { throw new RunnerException($"Project directory '{projectDirectory}' does not exist."); } if (!File.Exists(skeletonPath)) { throw new RunnerException("Skeleton file not found."); } projectDirectory = PathHelper.MakeAbsolutePath(Environment.CurrentDirectory, projectDirectory); outputDirectory = PathHelper.MakeAbsolutePath(projectDirectory, outputDirectory ?? RazorProjectConventions.DefaultIntermediateDirectory); RazorProject project = new RazorProject() { ProjectDirectory = projectDirectory, RootNamespace = rootNamespace, Items = new List <RazorProjectItem>(), IntermediateDirectory = outputDirectory, }; if (args.Options["-f", "--file"] != null) { foreach (string file in args.Options["-f", "--file"].Values) { foreach (string expandedFile in ResponseFile.ExpandStrings(file, project.ProjectDirectory)) { if (!HasPipeFormat(expandedFile, out var fullPath, out var projectPath)) { project.AddItem(expandedFile); } else if (!string.IsNullOrEmpty(fullPath)) { project.Items.Add(new RazorProjectItem() { FullPath = MakeAbsolutePath(fullPath), ProjectPath = projectPath }); } }