Example #1
0
        static int Main(string[] args)
        {
            // kefka --eol=lf path/to/file.txt -op output/path
            // kefka --eol=lf path/to/file.txt -of output/file.txt

            CmdLine      cmdLine   = new CmdLine(args);
            CmdProcessor processor = cmdLine.Parse();

            if (processor == null)
            {
                return(1);
            }

            if (processor.HasError())
            {
                return(PrintErrors(processor));
            }

            if (!processor.RunAndWait())
            {
                if (processor.HasError())
                {
                    return(PrintErrors(processor));
                }
            }

            return(0);
        }
Example #2
0
 private static int PrintErrors(CmdProcessor processor)
 {
     foreach (string error in processor.GetErrors())
     {
         Console.Error.WriteLine(error);
     }
     return(1);
 }
Example #3
0
        public CmdProcessor Parse()
        {
            if (_args.Length == 0)
            {
                DisplayHelp();
                return(null);
            }

            _type = _args[0].ToLower();

            CmdProcessor processor = null;

            if (_type == "--help" || _type == "-h" || _type == "help" || _type == "/?")
            {
                if (_args.Length == 1)
                {
                    DisplayHelp();
                }
                else
                {
                    string topic = "--" + _args[1].ToLower() + "=";
                    if ((processor = CmdProcessor.Factory(topic)) != null)
                    {
                        Console.WriteLine(processor.GetHelpText());
                    }
                    else
                    {
                        Console.WriteLine("Unrecognized help topic.");
                        DisplayHelp();
                    }
                }
                return(null);
            }
            if (_type == "--version" || _type == "-v")
            {
                Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                Console.WriteLine($"Kefka v{version}");
            }
            else if ((processor = CmdProcessor.Factory(_type)) != null)
            {
                if (!processor.ParseCmdLine(this))
                {
                    return(processor);
                }
            }
            else
            {
                DisplayHelp();
                return(null);
            }

            return(processor);
        }