public void Set_WhenSettingAValue_ShouldReturnTrue() { //Act string result = CLIParser.Cmd("SET name bob"); //Assert Assert.Equal(result, "True"); }
public void listTableTest() { TBDatabaseKeeper keeper = new Mock <TBDatabaseKeeper>().Object; Mock <DataKeeper> dkMock = new Mock <DataKeeper>(keeper); dkMock.Setup(mock => mock.GetTableNames()); string[] args = new string[] { "list", "tables" }; CLIParser cLIParser = new CLIParser(dkMock.Object); cLIParser.parseArguments(args); dkMock.Verify(mock => mock.GetTableNames(), Times.Once()); }
public void selectEntriesTest() { string tableName = "tableName"; TBDatabaseKeeper keeper = new Mock <TBDatabaseKeeper>().Object; Mock <DataKeeper> dkMock = new Mock <DataKeeper>(keeper); dkMock.Setup(mock => mock.SelectData(tableName, ">", "10")); string[] args = new string[] { "select", "from", tableName, "where", "column", ">", "10" }; CLIParser cLIParser = new CLIParser(dkMock.Object); cLIParser.parseArguments(args); dkMock.Verify(mock => mock.SelectData(tableName, ">", "10"), Times.Once()); }
public void createDatabaseTest() { string databaseName = "databaseName"; TBDatabaseKeeper keeper = new Mock <TBDatabaseKeeper>().Object; Mock <DataKeeper> dkMock = new Mock <DataKeeper>(keeper); dkMock.Setup(mock => mock.CreateDatabase(databaseName, path)); string[] args = new string[] { "create", "database", databaseName }; CLIParser cLIParser = new CLIParser(dkMock.Object); cLIParser.parseArguments(args); dkMock.Verify(mock => mock.CreateDatabase(databaseName, path), Times.Once()); }
public void createTableTest() { string tableName = "tableName"; TBDatabaseKeeper keeper = new Mock <TBDatabaseKeeper>().Object; Mock <DataKeeper> dkMock = new Mock <DataKeeper>(keeper); dkMock.Setup(mock => mock.CreateTable(tableName, new List <string>())); string[] args = new string[] { "create", "table", tableName }; CLIParser cLIParser = new CLIParser(dkMock.Object); cLIParser.parseArguments(args); dkMock.Verify(mock => mock.CreateTable(tableName, new List <string>()), Times.Once()); }
public void deleteEntriesTest() { string tableName = "tableName"; TBDatabaseKeeper keeper = new Mock <TBDatabaseKeeper>().Object; Mock <DataKeeper> dkMock = new Mock <DataKeeper>(keeper); dkMock.Setup(mock => mock.DeleteEntries(tableName, "column", 1, 3)); string[] args = new string[] { "delete", "from", tableName, "column", "1", "3" }; CLIParser cLIParser = new CLIParser(dkMock.Object); cLIParser.parseArguments(args); dkMock.Verify(mock => mock.DeleteEntries(tableName, "column", 1, 3), Times.Once()); }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); var configuration = builder.Build(); //var connectionString = configuration.GetSection("Secrets")["MySQLConnectionString"]; var frontierePersistance = new FrontiereStockageSQLite(); var accesseurPoona = new AccesseurPoonaParFichierCSV(); var importeurCompetition = new ImporteurDeCompetitionParFichierXML(frontierePersistance);; var frontiereCobad = new FrontiereCobad(frontierePersistance, accesseurPoona, importeurCompetition); var parser = new CLIParser(frontiereCobad); parser.Parse(args); }
do_parse ( string Command ) { Command_Line_Options parsed_command; // // Declare the various streams of characters and tokens for parsing the input // var input_stream = new AntlrInputStream(Command); // Create a stream that reads from the command line var lexer = new CLILexer(input_stream); // Create a lexer that feeds off of the input stream var tokens = new CommonTokenStream(lexer); // Create a buffer of tokens pulled from the lexer var parser = new CLIParser(tokens); // Create a parser that feeds off of the token buffer var tree = parser.start(); // Call the start rule in the grammar to build a parse tree from the input var my_listeners = new CLI_Listener_Overrides(); // Instantiate my listener override functions so they can be used by ParseTreeWalker // // Walk the parse tree and call all the listeners // ParseTreeWalker.Default.Walk(my_listeners, tree); // // Complex command strings may be placed in a script file and referenced using the "@file.txt" syntax. If a script file was specified, // then parse the contents of the file // if (my_listeners.parsed_command_line.script_file.Length != 0) { List <string> script_file = Program.find_files(my_listeners.parsed_command_line.script_file); parsed_command = Command_Parser.do_parse(File.ReadAllText(script_file.First())); } else { parsed_command = my_listeners.parsed_command_line; } // // /HELP shouldn't be specified with any other qualifiers or input files // if (parsed_command.help && (parsed_command.all || parsed_command.exclude_dlls.Count != 0 || parsed_command.exports || parsed_command.file_names.Count != 0 || parsed_command.imports || parsed_command.output.Length != 0 || parsed_command.recurse)) { throw new ArgumentException("/HELP is not valid with any other qualifiers or input file(s)"); } // // All other command formats require input file(s) // if (parsed_command.file_names.Count == 0 && !parsed_command.help) { throw new ArgumentException("Input file(s) not specified; try /HELP for more info"); } // // /EXCLUDE_DLLS is not compatible with /INCLUDE_DLLS // if (parsed_command.exclude_dlls.Count != 0 && parsed_command.include_dlls.Count != 0) { throw new ArgumentException("/EXCLUDE_DLLS and /INCLUDE_DLLS are mutually exclusive; try /HELP for more info"); } // // Ensure that either /EXPORTS or /IMPORTS (or both) was specified, when /HELP isn't specified // if (!parsed_command.help && (!parsed_command.exports && !parsed_command.imports)) { throw new ArgumentException("/EXPORTS or /IMPORTS (or both) must be specified; try /HELP for more info"); } // // Ensure that if /OUTPUT is specified, that /GENERATE is also specified // if (parsed_command.output.Length != 0 && !parsed_command.generate) { throw new ArgumentException("/OUTPUT requires that /GENERATE also be specified; try /HELP for more info"); } // // If /EXCLUDE_DLLS was specified, then convert the list of files (they may contain wildcards) to regular expressions. // The regular expressions are compiled, because the comparison will typically happen frequently // if (parsed_command.exclude_dlls.Count != 0) { parsed_command.exclude_dlls.Distinct().ToList(); // Ensure there aren't any duplicates var regex_list = new List <Regex> (); // // Look at each file name specified // foreach (string name in parsed_command.exclude_dlls) { var path = Path.GetDirectoryName(name); // // Ensure that there isn't a path on the file name // if (path.Length == 0) { regex_list.Add(new Regex(Program.wildcard_to_regexp(name), RegexOptions.IgnoreCase | RegexOptions.Compiled)); } else { throw new ArgumentException("Path not allowed on /EXCLUDE_DLLS file names; try /HELP for more info"); } } parsed_command.excluded_dlls_regex = regex_list; } // // If /INCLUDE_DLLS was specified, then convert the list of files (they may contain wildcards) to regular expressions. // The regular expressions are compiled, because the comparison will typically happen frequently // if (parsed_command.include_dlls.Count != 0) { parsed_command.include_dlls.Distinct().ToList(); // Ensure there aren't any duplicates var regex_list = new List <Regex> (); // // Look at each file name specified // foreach (string name in parsed_command.include_dlls) { var path = Path.GetDirectoryName(name); // // Ensure that there isn't a path on the file name // if (path.Length == 0) { regex_list.Add(new Regex(Program.wildcard_to_regexp(name), RegexOptions.IgnoreCase | RegexOptions.Compiled)); } else { throw new ArgumentException($"Path not allowed on /INCLUDE_DLLS file name {name}; try /HELP for more info"); } } parsed_command.included_dlls_regex = regex_list; } // // If /DATABASE was not specified, then set the default // if (parsed_command.database.Length == 0) { var path = Path.GetFullPath("."); parsed_command.database = Path.Combine(path, "Win32API.accdb"); } else { // // Take the specified database file/path, which may contain relative paths, and convert it to an absolute path // var path = Path.GetFullPath(parsed_command.database); // // If a directory was specified but not a database file, then set the database file name to the default // var file_attrs = File.GetAttributes(path); if ((file_attrs & FileAttributes.Directory) != 0) { path = Path.Combine(path, "Win32API.accdb"); } parsed_command.database = path; } // // If /OUTPUT was not specified, then set the default // if (parsed_command.output.Length == 0) { parsed_command.output = "TraceAPI.cpp"; } else { // // Take the specified output file/path, which may contain relative paths, and convert it to an absolute path // var path = Path.GetFullPath(parsed_command.output); // // If a directory was specified but not an output file, then set the output file name to the default // var file_attrs = File.GetAttributes(path); if ((file_attrs & FileAttributes.Directory) != 0) { path = Path.Combine(path, "TraceAPI.cpp"); } parsed_command.output = path; } // // Display the results of the parse // if (parsed_command.verbose) { Console.WriteLine($"Command line: {Command}"); Console.WriteLine($"All:\t\t{parsed_command.all}"); Console.WriteLine($"Database:\t{parsed_command.database}"); Console.WriteLine($"Exclude_dlls:\t{string.Join (", ", parsed_command.exclude_dlls)}"); Console.WriteLine($"Exports:\t{parsed_command.exports}"); Console.WriteLine($"Generate:\t{parsed_command.generate}"); Console.WriteLine($"Help:\t\t{parsed_command.help}"); Console.WriteLine($"Imports:\t{parsed_command.imports}"); Console.WriteLine($"Include_dlls:\t{string.Join (", ", parsed_command.include_dlls)}"); Console.WriteLine($"Output:\t\t{parsed_command.output}"); Console.WriteLine($"Recurse:\t{parsed_command.recurse}"); Console.WriteLine($"Verbose:\t{parsed_command.verbose}"); Console.WriteLine($"Webscrape:\t{parsed_command.webscrape}"); Console.WriteLine($"Input files:\t{string.Join (", ", parsed_command.file_names)}"); Console.WriteLine(); } return(parsed_command); } // End parse
public ActionResult <string> Get([FromQuery] string cmd) { return(CLIParser.Cmd(cmd)); }
public static void Main(string[] args) { CLIParser.Parse(new List <string>(args), Run); }