Ejemplo n.º 1
0
        public override bool ParseCmdLine(CmdLine cmdLine)
        {
            // kefka --concat path/to/file1.js path/to/file2.js
            //       -of output/file.js -d=lf -dn=2 -e=lf

            _delimiterRepeat = 1;

            _inputFilesParam = new List <string>();
            bool?isOutputFile = null;

            for (int i = 1; i < cmdLine._args.Length; i++)
            {
                string arg = cmdLine._args[i];

                if (arg == "-of")
                {
                    isOutputFile = true;
                    continue;
                }
                else if (isOutputFile == true)
                {
                    _outputFileParam = arg;
                    isOutputFile     = false;
                    continue;
                }

                if (arg.StartsWith("-d="))
                {
                    ParseEolTypeError error = EolUtil.ParseEqualsEolType(arg, out string eolType);
                    if (error != ParseEolTypeError.Success)
                    {
                        AppendError($"Missing or invalid -d= param value.");
                        return(false);
                    }
                    _eolTypeDelimiter = eolType;
                    continue;
                }
                else if (arg.StartsWith("-dn="))
                {
                    string[] tok = arg.Split('=');
                    if (!int.TryParse(tok[1], out int delimRepeat))
                    {
                        AppendError("Missing or invalid -dn= param value.");
                        return(false);
                    }
                    _delimiterRepeat = delimRepeat;
                    continue;
                }
                else if (arg.StartsWith("-e="))
                {
                    ParseEolTypeError error = EolUtil.ParseEqualsEolType(arg, out string eolType);
                    if (error != ParseEolTypeError.Success)
                    {
                        AppendError($"Missing or invalid -e= param value.");
                        return(false);
                    }
                    _eofEolType = eolType;
                    continue;
                }

                _inputFilesParam.Add(arg);
            }

            if (_inputFilesParam.Count == 0)
            {
                AppendError("Missing [input-files] param.");
                return(false);
            }

            if (string.IsNullOrWhiteSpace(_outputFileParam))
            {
                AppendError("[output-file] param required.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        override public bool ParseCmdLine(CmdLine cmdLine)
        {
            ParseEolTypeError error = EolUtil.ParseEqualsEolType(cmdLine._type, out string eolType);
            if (error != ParseEolTypeError.Success)
            {
                AppendError($"Missing or invalid -eol= param value.");
                return false;
            }
            _eolTypeParam = eolType;

            // kefka --eol=lf path/to/file.txt -op output/path
            // kefka --eol=lf path/to/file.txt -of output/file.txt

            _inputFilesParam = new List<string>();
            bool? isOutputPath = null;
            bool? isOutputFile = null;
            for (int i = 1; i < cmdLine._args.Length; i++)
            {
                string arg = cmdLine._args[i];

                if (isOutputPath == null && arg == "-op")
                {
                    isOutputPath = true;
                    continue;
                }
                else if (isOutputPath == true)
                {
                    _outputPathParam = arg;
                    isOutputPath = false;
                    break;
                }

                if (isOutputFile == null && arg == "-of")
                {
                    isOutputFile = true;
                    continue;
                }
                else if (isOutputFile == true)
                {
                    _outputFileParam = arg;
                    isOutputFile = false;
                    break;
                }

                if (arg == "--no-remove-bom")
                {
                    _removeBom = false;
                    continue;
                }

                if (arg == "--in-place")
                {
                    _inPlace = true;
                    continue;
                }

                _inputFilesParam.Add(arg);
            }

            if (_inputFilesParam.Count == 0)
            {
                AppendError("Missing [input-files] param.");
                return false;
            }

            if (!_inPlace)
            {
                bool hasOutputPath = !string.IsNullOrWhiteSpace(_outputPathParam);
                bool hasOutputFile = !string.IsNullOrWhiteSpace(_outputFileParam);

                if (isOutputPath == true && !hasOutputPath)
                {
                    AppendError("Missing [output-path] param.");
                    return false;
                }
                else if (isOutputFile == true && !hasOutputFile)
                {
                    AppendError("Missing [output-file] param.");
                    return false;
                }

                if (!hasOutputPath && !hasOutputFile)
                {
                    AppendError("[output-path] or [output-file] param required.");
                    return false;
                }
                else if (hasOutputPath && hasOutputFile)
                {
                    AppendError("Cannot have both [output-path] and [output-file] params.");
                    return false;
                }

                if (hasOutputFile && _inputFilesParam.Count > 1)
                {
                    AppendError("Single [output-file] with multiple input files. Maybe you meant to use -op instead?");
                    return false;
                }
            }

            return true;
        }