Exemplo n.º 1
0
        public int Main(string[] args)
        {
            CommandLineOptions options = _commandLineParser.ParseCommandLine(args);

            if (options == null)
            {
                _consoleAdapter.WriteLine(GetUsageString());
                return(1);
            }

            _directory = options.RepoDirectory;

            if (!_fileSystem.DirectoryExists(_directory))
            {
                _consoleAdapter.WriteLine($"Directory \"{_directory}\" doesn't exist.  Failed");
                return(1);
            }

            // If an exclude file is specified, load the exclusions from file
            var exclusions = new List <string>();

            if (!string.IsNullOrEmpty(options.ExcludeFile))
            {
                if (!_fileSystem.FileExists(options.ExcludeFile))
                {
                    _consoleAdapter.WriteLine($"Exclude file \"{options.ExcludeFile}\" doesn't exist.  Failed");
                    return(1);
                }
                exclusions = _excludeFileParser.ParseExcludeFile(options.ExcludeFile);
                exclusions = _excludeFileParser.PrependRepoRootDir(options.RepoDirectory, exclusions);
            }

            bool hasChanges = false;

            foreach (var file in GetFilesForProcessing(options))
            {
                if (!_fileSystem.FileExists(file))
                {
                    _consoleAdapter.WriteLine($"File not found, skipping {file}");
                    continue;
                }

                hasChanges |= MakeFixesOnFile(file, options.Action, exclusions);
            }

            if (options.FailOnHCS && hasChanges)
            {
                return(1);
            }

            return(0);
        }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            var parsedCommandLine = commandLineParser.ParseCommandLine(String.Format(DescribeCommand, Changeset));
            var invoke            = this.processWrapper.Invoke(parsedCommandLine.Item1, parsedCommandLine.Item2);

            if (invoke.Item1 != 0)
            {
                this.ThrowTerminatingError(new ErrorRecord(new Exception(string.Join(Environment.NewLine, invoke.Item2)), $"Non zero return code: {invoke.Item1}", ErrorCategory.OperationStopped, this));
            }

            var changeset = describeParser.Parse(invoke.Item2);

            this.cmdlet.WriteObject(changeset);
        }
Exemplo n.º 3
0
        public static void TestCommandLineParser(ICommandLineParser parser, CommandLineSplitter splitter, string line, CommandLineItem[] expectedItems)
        {
            var _commandLine = splitter.ParseString(line);
            var _actualItems = parser.ParseCommandLine(_commandLine);

            for (var _i = 0; _i < expectedItems.Length && _i < _actualItems.Count; _i++)
            {
                Assert.Equal(expectedItems[_i].ToString(), _actualItems[_i].ToString(), StringComparer.Ordinal);
                Assert.Equal(expectedItems[_i], _actualItems[_i]);
            }

            Assert.Equal(expectedItems.Length, _actualItems.Count);
            Assert.True(expectedItems.SequenceEqual(_actualItems));

            Assert.Equal(_commandLine.Value, splitter.ParseString(_commandLine.Value).Value);
        }
        public int Extract()
        {
            logger.LogToConsole("Invoking: " + p4ChangesCommandLine);
            var parsedCommand = this.commandLineParser.ParseCommandLine(p4ChangesCommandLine);

            var invoke = this.processWrapper.Invoke(parsedCommand.Item1, parsedCommand.Item2);

            if (invoke.Item1 != 0)
            {
                return(invoke.Item1);
            }

            var changes = changesParser.Parse(invoke.Item2);

            logger.LogToConsole($"Found {changes.Count} changesets to parse");

            this.bugDatabaseProcessor.ProcessCache(this.changesetProcessor);

            int i = 0;

            this.stopWatch.Restart();

            foreach (var change in changes)
            {
                ReportProgressAfterOneMinute(i, changes);

                var cmd = commandLineParser.ParseCommandLine(String.Format(p4DescribeCommandLine, change));

                var describeInvoke = this.processWrapper.Invoke(cmd.Item1, cmd.Item2);
                if (describeInvoke.Item1 != 0)
                {
                    this.stopWatch.Stop();
                    return(describeInvoke.Item1);
                }

                changesetProcessor.ProcessChangeset(describeParser.Parse(describeInvoke.Item2));

                i++;
            }
            this.stopWatch.Stop();

            this.outputProcessor.ProcessOutput(outputType, outputFile, this.changesetProcessor.Output);
            return(0);
        }