From 90c7b2c4e675175a5b429d4467e65b22fc39b2d8 Mon Sep 17 00:00:00 2001 From: kiran francis Date: Sun, 6 Aug 2023 17:46:27 +0200 Subject: [PATCH] Adding input configuration file option using -i:config.txt --- SimplySerial/SimplySerial.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/SimplySerial/SimplySerial.cs b/SimplySerial/SimplySerial.cs index 51ebc45..479b67b 100644 --- a/SimplySerial/SimplySerial.cs +++ b/SimplySerial/SimplySerial.cs @@ -410,9 +410,37 @@ namespace SimplySerial // sort the parameters so that they get processed in order of priority (i.e. 'quiet' option gets processed before something that would normally result in console output, etc.) Array.Sort(args, new ArgumentSorter()); + List argList = args.ToList(); // iterate through command-line arguments foreach (string arg in args) + { + // split argument into components based on 'key:value' formatting + string[] argument = arg.Split(new[] { ':' }, 2); + argument[0] = argument[0].ToLower(); + // input config file + if (argument[0].StartsWith("i")) + { + if (argument.Length != 2) + { + ExitProgram(("Input filename not provided"), exitCode: -1); + } + + try + { + string[] lines = File.ReadAllLines(argument[1]); + argList = lines.ToList(); + } + catch (Exception e) + { + ExitProgram(("Invalid file name <" + argument[1] + ">"), exitCode: -1); + } + break; + } + } + + // iterate through command-line arguments + foreach (string arg in argList) { // split argument into components based on 'key:value' formatting string[] argument = arg.Split(new[] { ':' }, 2); @@ -742,6 +770,7 @@ namespace SimplySerial Console.WriteLine(" -encoding:ENC UTF8 | ASCII | RAW"); Console.WriteLine(" -noclear Don't clear the terminal screen on connection."); Console.WriteLine(" -nostatus Block status/title updates from virtual terminal sequences."); + Console.WriteLine(" -input Input file whose each line contain an option without '-' infront. eg: com:COM1"); Console.WriteLine("\nPress CTRL-X to exit a running instance of SimplySerial.\n"); }