예제 #1
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            var visitor = new CheckOutBranchVisitor();

            _algorithm.TraverseDependencies(visitor, _options.Directory);

            if (visitor.ReturnCode == ReturnCode.Success)
            {
                _console.WriteLine("Successfully cloned all dependencies");
            }

            return(visitor.ReturnCode);
        }
예제 #2
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            IVisitor visitor = new NullVisitor();

            _algorithm.TraverseDependencies(visitor, _options.Directory);

            if (visitor.ReturnCode == ReturnCode.Success)
            {
                _console.WriteLine("Successfully cloned all dependencies");
            }

            visitor = new CheckOutDependencyBranchVisitor();
            _algorithm.Reset();
            _algorithm.TraverseDependencies(visitor, _options.Directory);

            if (visitor.ReturnCode == ReturnCode.Success)
            {
                _console.WriteLine("All dependencies on the correct branch");
            }

            return(visitor.ReturnCode);
        }
예제 #3
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            IVisitor visitor = new CheckOutBranchVisitor();

            _algorithm.TraverseDependencies(visitor, _options.Directory);

            if (visitor.ReturnCode != ReturnCode.Success)
            {
                _console.WriteLine("Could not ensure the correct branch on all dependencies.");
                return(visitor.ReturnCode);
            }

            _algorithm.Reset();
            visitor = new BuildAndUpdateDependenciesVisitor();
            _algorithm.TraverseDependencies(visitor, _options.Directory);

            if (visitor.ReturnCode == ReturnCode.Success)
            {
                _console.WriteLine("Update complete!");
            }

            return(visitor.ReturnCode);
        }
예제 #4
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            if (string.IsNullOrEmpty(_options.BranchName))
            {
                return(ReturnCode.InvalidArguments);
            }

            IVisitor visitor = new CheckOutBranchVisitor(_options.BranchName, _options.CreateBranch);

            _algorithm.TraverseDependencies(visitor, _options.Directory);

            if (visitor.ReturnCode != ReturnCode.Success)
            {
                return(visitor.ReturnCode);
            }

            _algorithm.Reset();

            visitor = new VerifyCorrectBranchVisitor(new List <string>());
            _algorithm.TraverseDependencies(visitor, _options.Directory);

            return(visitor.ReturnCode);
        }
예제 #5
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            var verifyVisitor = new VerifyCorrectBranchVisitor(_options.Dependencies);

            _algorithm.TraverseDependencies(verifyVisitor, _options.Directory);

            if (verifyVisitor.ReturnCode != ReturnCode.Success)
            {
                _console.WriteLine("Not all dependencies are on the correct branch.");
                return(verifyVisitor.ReturnCode);
            }

            _console.WriteLine();
            _algorithm.Reset();
            var buildAndUpdateVisitor = new BuildAndUpdateDependenciesVisitor(_options.Dependencies);

            _algorithm.TraverseDependencies(buildAndUpdateVisitor, _options.Directory);

            if (buildAndUpdateVisitor.ReturnCode == ReturnCode.Success)
            {
                if (buildAndUpdateVisitor.UpdatedPackages.Any())
                {
                    _console.WriteLine("Updated packages: ");
                    foreach (var package in buildAndUpdateVisitor.UpdatedPackages)
                    {
                        _console.WriteLine($"    {package}");
                    }
                    _console.WriteLine("Update complete!");
                }
                else
                {
                    _console.WriteLine("nothing was updated");
                }
            }

            return(buildAndUpdateVisitor.ReturnCode);
        }
예제 #6
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            var visitor = CreateVisitor(Options);

            _algorithm.TraverseDependencies(visitor, Options.Directory);

            var code = visitor.ReturnCode;

            if (code == ReturnCode.Success)
            {
                var origColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("project:");
                Console.WriteLine($"    dir: {Options.Directory}");
                Console.WriteLine();
                Console.ForegroundColor = origColor;

                code = AfterDependencyTraversal(Options);
            }

            return(code);
        }
예제 #7
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <returns>The return code.</returns>
        public ReturnCode Execute()
        {
            bool[] flags =
            {
                _options.Delete,
                _options.ListMerged
            };

            // only one mutually exclusive flag can be set.
            if (flags.Count(b => b) > 1)
            {
                return(ReturnCode.InvalidArguments);
            }

            // force delete can only be specified if delete is specified.
            if (!_options.Delete && _options.ForceDelete)
            {
                return(ReturnCode.InvalidArguments);
            }

            // if delete is specified the branch name must also be specified.
            if (_options.Delete && string.IsNullOrEmpty(_options.BranchName))
            {
                return(ReturnCode.InvalidArguments);
            }

            if (_options.ListMerged && !string.IsNullOrEmpty(_options.BranchName))
            {
                return(ReturnCode.InvalidArguments);
            }

            IVisitor          visitor;
            string            successMessage;
            Func <ReturnCode> postTraverse = null;

            if (_options.Delete)
            {
                visitor        = new DeleteBranchVisitor(_options.BranchName, _options.ForceDelete);
                successMessage = $"Successfully deleted the {_options.BranchName} branch from all repositories.";
            }
            else if (_options.ListMerged)
            {
                visitor        = new ListMergedBranchesVisitor();
                successMessage = string.Empty;
                postTraverse   = () =>
                {
                    _git.WorkingDirectory = _options.Directory;
                    return(_git.ListMergedBranches());
                };
            }
            else if (!string.IsNullOrEmpty(_options.BranchName))
            {
                visitor        = new CreateBranchVisitor(_options.BranchName);
                successMessage = $"Successfully created the {_options.BranchName} branch in all repositories.";
            }
            else
            {
                visitor        = new ListAllBranchesVisitor();
                successMessage = string.Empty;
                postTraverse   = () =>
                {
                    _git.WorkingDirectory = _options.Directory;
                    return(_git.ListAllBranches());
                };
            }

            _algorithm.TraverseDependencies(visitor, _options.Directory);

            var code = visitor.ReturnCode;

            if (code == ReturnCode.Success && postTraverse != null)
            {
                var origColor = _console.ForegroundColor;
                _console.ForegroundColor = ConsoleColor.Green;
                _console.WriteLine("project:");
                _console.WriteLine($"    dir: {_options.Directory}");
                _console.WriteLine();
                _console.ForegroundColor = origColor;

                code = postTraverse();
            }

            if (code == ReturnCode.Success)
            {
                _console.WriteLine(successMessage);
            }


            return(visitor.ReturnCode);
        }