Пример #1
0
        public static void Main(string[] args)
        {
            string sourcePattern  = "";
            string targetPattern  = "";
            string workingRepoDir = Directory.GetCurrentDirectory() + @"\";
            bool   show_help      = false;

            var p = new OptionSet()
            {
                /*{
                 *  "d|directory",
                 *  "Specifies the root directory of the repo to use; default is current directory.",
                 *  (string v) => workingRepoDir = v
                 * },
                 */
                {
                    "h|help",
                    "Displays this help for \"move\"",
                    v => show_help = v != null
                },
                { "r|redirect", "Indicates that moved file should be replaced with a redirect file to the new target; default is true.", v => redirects = true },
                { "c|continue", "Indicates that should a non-fatal error occur, as much work as is possible will complete and the error is reported for followup.", v => @continue = true }
            };

            List <string> argList;

            try {
                argList = p.Parse(args);
            }
            catch (OptionException e) {
                Console.Write("move: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'move --help' for more information.");
                return;
            }

            if (show_help)
            {
                ShowHelp(p);
                return;
            }

            GitMover mover = null;

            try
            {
                mover = new GitMover(workingRepoDir, argList[0], argList[1], redirects, @continue);
                mover.Move();
                mover.Dispose();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: {0} ", ex.Message);
                Console.ResetColor();
                ShowHelp(p);
                if (mover != null)
                {
                    mover.Unwind();
                    mover.Dispose();
                }
            }
            Console.WriteLine("done");
            //Console.ReadLine();
        }
Пример #2
0
        public static void Main(string[] args)
        {
            string sourcePattern  = "";
            string targetPattern  = "";
            string workingRepoDir = Directory.GetCurrentDirectory() + @"\";
            bool   show_help      = false;

            var p = new OptionSet()
            {
                /*{
                 *  "d|directory",
                 *  "Specifies the root directory of the repo to use; default is current directory.",
                 *  (string v) => workingRepoDir = v
                 * },
                 */
                {
                    "h|help",
                    "Displays this help for \"move\"",
                    v => show_help = v != null
                },
                { "r|redirect", "Indicates that moved file should be replaced with a redirect file to the new target; default is false.", v => redirects = true },
                { "c|commit", "Indicates that all changes should be committed; default is to leave all changes **staged** (\"added\", in git terminology, but not committed) so that \"git diff --cached\" will immediately display the changes.", v => commit = true }
            };

            List <string> argList;

            try {
                argList = p.Parse(args);
            }
            catch (OptionException e) {
                Console.Write("move: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'move --help' for more information.");
                return;
            }

            if (show_help)
            {
                ShowHelp(p);
                return;
            }

            GitMover mover = null;

            try
            {
                mover = new GitMover(workingRepoDir, argList[0], argList[1], redirects, commit);
                mover.Move();
                mover.Dispose();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: {0}: ", ex.Message);
                Console.ResetColor();
                ShowHelp(p);
                if (mover != null)
                {
                    mover.Unwind();
                    mover.Dispose();
                }
            }
            Console.WriteLine("done");
            Console.ReadLine();
        }
Пример #3
0
        public static void Main(string[] args)
        {
            string repoDir = "";

            Options options = new Options();

            try
            {
                if (CommandLine.Parser.Default.ParseArguments(args, options))
                {
                    if (options.ShowHelp)
                    {
                        Console.WriteLine(CommandLine.Text.HelpText.AutoBuild(options));
                        //Exit the app without doing anything
                        return;
                    }

                    if (String.IsNullOrEmpty(options.RepoDir))
                    {
                        // Use the current directory if the user didn't specify --repo-dir
                        repoDir = Directory.GetCurrentDirectory() + @"\";
                    }
                    else
                    {
                        repoDir = options.RepoDir + @"\";
                    }
                }
                else
                {
                    Console.WriteLine("Command line arguments not parsed successfully. Raw args were:");
                    Console.WriteLine(String.Join(" | ", args));
                }
            }
            catch (Exception e)
            {
                Console.Write("move: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try 'move --help' for more information.");
                return;
            }

            GitMover mover = null;

            try
            {
                mover = new GitMover(repoDir, options.Source, options.Destination, options.Redirect, options.Continue, options.DoCommit);
                mover.Move();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: {0} ", ex.Message);
                Console.WriteLine("Stack trace: {0} ", ex.StackTrace);
                Console.ResetColor();

                if (mover != null)
                {
                    Console.WriteLine("Unwinding...");
                    mover.Unwind();
                }

                // Pause to allow user to view exception message
                Console.WriteLine("\nHit ENTER to exit...");
                Console.ReadLine();
            }
            finally
            {
                if (mover != null)
                {
                    mover.Dispose();
                }
            }

            Console.WriteLine("Done.");
        }