List of all commands known by the command line tools. Commands are implementations of the TextBuiltin class, with a required command attribute to insert additional documentation and add some extra information such as if the command is common and completed. Commands may be registered by adding them to the Commands.xml file. The Commands.xml file should contain: a. The command name including namespace. b. The website address for command specific online help.(optional)
예제 #1
0
        /// <summary>
        /// Display the commands that start with the specified string.
        /// </summary>
        /// <param name="s"></param>
        /// <returns>Returns true if matches exist, otherwise false.</returns>
        private static bool ShowCommandMatches(String s)
        {
            CommandCatalog    catalog = new CommandCatalog();
            List <CommandRef> matches = catalog.StartsWith(s);

            if (matches.Count > 0)
            {
                foreach (CommandRef c in matches)
                {
                    Console.WriteLine("git: '" + s + "' is not a git command. See 'git --help'.");
                    Console.WriteLine();
                    Console.WriteLine("Did you mean this?");
                    Console.Write("      ");
                    Console.Write(c.getName());
                    for (int i = c.getName().Length + 8; i < 31; i++)
                    {
                        Console.Write(" ");
                    }
                    Console.Write(c.getUsage());
                    Console.WriteLine();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Display the complete commands in GitSharp.
        /// </summary>
        private static void ShowComplete()
        {
            CommandCatalog catalog = new CommandCatalog();

            foreach (CommandRef c in catalog.Complete())
            {
                Console.Write("      ");
                Console.Write(c.getName());
                for (int i = c.getName().Length + 8; i < 31; i++)
                {
                    Console.Write(" ");
                }
                Console.Write(c.getUsage());
                Console.WriteLine();
            }
        }
예제 #3
0
        /// <summary>
        /// Display the main offline help screen.
        /// </summary>
        private static void ShowHelp()
        {
            Console.Write("usage: git ");
            Console.Write(string.Join(" ", options.Select(o => "[--" + string.Join("|-", o.Names) + "]").ToArray()));
            Console.WriteLine("\nCOMMAND [ARGS]\n\nThe most commonly used git commands are:");
            options.WriteOptionDescriptions(Console.Error);
            Console.WriteLine();

            CommandCatalog catalog = new CommandCatalog();

            foreach (CommandRef c in catalog.Common())
            {
                Console.Write("      ");
                Console.Write(c.getName());
                for (int i = c.getName().Length + 8; i < 31; i++)
                {
                    Console.Write(" ");
                }
                Console.Write(c.getUsage());
                Console.WriteLine();
            }
            Console.Error.WriteLine();
            Console.Error.Write(@"See 'git help COMMAND' for more information on a specific command.");
        }
예제 #4
0
 /// <summary>
 /// Display the incomplete commands in GitSharp. Primarily for development use.
 /// </summary>
 private static void ShowIncomplete()
 {
     CommandCatalog catalog = new CommandCatalog();
     foreach (CommandRef c in catalog.Incomplete())
     {
         Console.Write("      ");
         Console.Write(c.getName());
         for (int i = c.getName().Length + 8; i < 31; i++)
             Console.Write(" ");
         Console.Write(c.getUsage());
         Console.WriteLine();
     }
 }
예제 #5
0
        /// <summary>
        /// Display the main offline help screen.
        /// </summary>
        private static void ShowHelp()
        {
            Console.Write("usage: git ");
            Console.Write(string.Join(" ", options.Select(o => "[--" + string.Join("|-", o.Names) + "]").ToArray()));
            Console.WriteLine("\nCOMMAND [ARGS]\n\nThe most commonly used git commands are:");
            options.WriteOptionDescriptions(Console.Error);
            Console.WriteLine();

            CommandCatalog catalog = new CommandCatalog();
            foreach (CommandRef c in catalog.Common())
            {
                Console.Write("      ");
                Console.Write(c.getName());
                for (int i = c.getName().Length + 8; i < 31; i++)
                    Console.Write(" ");
                Console.Write(c.getUsage());
                Console.WriteLine();
            }
            Console.Error.WriteLine();
            Console.Error.Write(@"See 'git help COMMAND' for more information on a specific command.");
        }
예제 #6
0
 /// <summary>
 /// Display the commands that start with the specified string.
 /// </summary>
 /// <param name="s"></param>
 /// <returns>Returns true if matches exist, otherwise false.</returns>
 private static bool ShowCommandMatches(String s)
 {
     CommandCatalog catalog = new CommandCatalog();
     List<CommandRef> matches = catalog.StartsWith(s);
     if (matches.Count > 0)
     {
         foreach (CommandRef c in matches)
         {
             Console.WriteLine("git: '" + s + "' is not a git command. See 'git --help'.");
             Console.WriteLine();
             Console.WriteLine("Did you mean this?");
             Console.Write("      ");
             Console.Write(c.getName());
             for (int i = c.getName().Length + 8; i < 31; i++)
                 Console.Write(" ");
             Console.Write(c.getUsage());
             Console.WriteLine();
         }
         return true;
     }
     else
     {
         return false;
     }
 }
예제 #7
0
        /// <summary>
        /// Execute the command line
        /// </summary>
        /// <param name="argv"></param>
        private static void execute(string[] argv)
        {
            if (argv.Count() == 0)
            {
                ShowHelp();
            }
            else if (!argv[0].StartsWith("--") && !argv[0].StartsWith("-"))
            {

                CommandCatalog catalog = new CommandCatalog();
                CommandRef subcommand = catalog.Get(argv[0]);
                string gitdir = null;

                if (subcommand != null)
                {
                    TextBuiltin cmd = subcommand.Create();
                    List<String> args = argv.ToList();
                    GitSharp.Repository repo = null;

                    try
                    {
                        for (int x = 0; x < args.Count; x++)
                        {
                            if (args[x].IndexOf("--git-dir=") > -1)
                            {
                                if (args[x].Length > 10)
                                {
                                    gitdir = args[x].Substring(10);
                                    args.RemoveAt(x);
                                    break;
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.WriteLine("error: can't find git directory");
                            Git.DefaultOutputStream.Flush();
                        }
                        Exit(1);
                    }

                    if (cmd.RequiresRepository)
                    {
                        if (gitdir == null)
                        {
                            gitdir = Commands.AbstractCommand.FindGitDirectory(null, true, false);
                            if (gitdir == null)
                            {
                                Console.Error.WriteLine("fatal: Not a git repository (or any of the parent directories): .git");
                                Exit(0);
                            }
                        }

                        repo = new GitSharp.Repository(gitdir);
                        cmd.Init(repo, gitdir);
                    }
                    else
                        cmd.Init(null, gitdir);

                    try
                    {
                        // Remove the subcommand from the command line
                        args.RemoveAt(0);
                        cmd.Execute(args.ToArray());
                    }
                    finally
                    {
                        if (Git.DefaultOutputStream != null)
                            Git.DefaultOutputStream.Flush();

                        if (repo != null)
                            repo.Close();
                    }
                }
                else
                {
                    // List all available commands starting with argv[0] if the command
                    // specified does not exist.
                    // If no commands exist starting with argv[0], show the help screen.
                    if (!ShowCommandMatches(argv[0]))
                        ShowHelp();
                }
            }
            else
            {
                // If the first argument in the command line is an option (denoted by starting with - or --),
                // no subcommand has been specified in the command line.
                try
                {
                    options.Parse(argv, out arguments);
                }
                catch (OptionException err)
                {
                    if (arguments.Count > 0)
                    {
                        Console.Error.WriteLine("fatal: " + err.Message);
                        Exit(1);
                    }
                }
            }
            Exit(0);
        }
예제 #8
0
        /// <summary>
        /// Execute the command line
        /// </summary>
        /// <param name="argv"></param>
        private static void execute(string[] argv)
        {
            if (argv.Count() == 0)
            {
                ShowHelp();
            }
            else if (!argv[0].StartsWith("--") && !argv[0].StartsWith("-"))
            {
                CommandCatalog catalog    = new CommandCatalog();
                CommandRef     subcommand = catalog.Get(argv[0]);
                string         gitdir     = null;

                if (subcommand != null)
                {
                    TextBuiltin         cmd  = subcommand.Create();
                    List <String>       args = argv.ToList();
                    GitSharp.Repository repo = null;

                    try
                    {
                        for (int x = 0; x < args.Count; x++)
                        {
                            if (args[x].IndexOf("--git-dir=") > -1)
                            {
                                if (args[x].Length > 10)
                                {
                                    gitdir = args[x].Substring(10);
                                    args.RemoveAt(x);
                                    break;
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.WriteLine("error: can't find git directory");
                            Git.DefaultOutputStream.Flush();
                        }
                        Exit(1);
                    }

                    if (cmd.RequiresRepository)
                    {
                        if (gitdir == null)
                        {
                            gitdir = Commands.AbstractCommand.FindGitDirectory(null, true, false);
                            if (gitdir == null)
                            {
                                Console.Error.WriteLine("fatal: Not a git repository (or any of the parent directories): .git");
                                Exit(0);
                            }
                        }

                        repo = new GitSharp.Repository(gitdir);
                        cmd.Init(repo, gitdir);
                    }
                    else
                    {
                        cmd.Init(null, gitdir);
                    }

                    try
                    {
                        // Remove the subcommand from the command line
                        args.RemoveAt(0);
                        cmd.Execute(args.ToArray());
                    }
                    finally
                    {
                        if (Git.DefaultOutputStream != null)
                        {
                            Git.DefaultOutputStream.Flush();
                        }

                        if (repo != null)
                        {
                            repo.Close();
                        }
                    }
                }
                else
                {
                    // List all available commands starting with argv[0] if the command
                    // specified does not exist.
                    // If no commands exist starting with argv[0], show the help screen.
                    if (!ShowCommandMatches(argv[0]))
                    {
                        ShowHelp();
                    }
                }
            }
            else
            {
                // If the first argument in the command line is an option (denoted by starting with - or --),
                // no subcommand has been specified in the command line.
                try
                {
                    options.Parse(argv, out arguments);
                }
                catch (OptionException err)
                {
                    if (arguments.Count > 0)
                    {
                        Console.Error.WriteLine("fatal: " + err.Message);
                        Exit(1);
                    }
                }
            }
            Exit(0);
        }
예제 #9
0
파일: Program.cs 프로젝트: Squelch/GitSharp
        /// <summary>
        /// Execute the command line
        /// </summary>
        /// <param name="argv"></param>
        private static void execute(string[] argv)
        {
            if (argv.Count() == 0)
            {
                ShowHelp();
            }
            else if (!argv[0].StartsWith("--") && !argv[0].StartsWith("-"))
            {

                CommandCatalog catalog = new CommandCatalog();
                CommandRef subcommand = catalog.Get(argv[0]);
                if (subcommand != null)
                {
                    TextBuiltin cmd = subcommand.Create();
                    if (cmd.RequiresRepository())
                    {
                        if (gitdir == null)
                            gitdir = findGitDir();
                        if (gitdir == null || !gitdir.IsDirectory())
                        {
                            Console.Error.WriteLine("error: can't find git directory");
                            Exit(1);
                        }
                        cmd.Init(new Repository(gitdir), gitdir.FullName);
                    }
                    else
                    {
                        cmd.Init(null, null);
                    }

                    try
                    {
                        // Remove the subcommand from the command line
                        List<String> args = argv.ToList();
                        args.RemoveAt(0);
                        cmd.Execute(args.ToArray());
                    }
                    finally
                    {
                        if (Console.Out != null)
                            Console.Out.Flush();
                    }
                }
                else
                {
                    // List all available commands starting with argv[0] if the command
                    // specified does not exist.
                    // If no commands exist starting with argv[0], show the help screen.
                    if (!ShowCommandMatches(argv[0]))
                        ShowHelp();
                }
            }
            else
            {
                // If the first argument in the command line is an option (denoted by starting with - or --),
                // no subcommand has been specified in the command line.
                try
                {
                    arguments = options.Parse(argv);
                }
                catch (OptionException err)
                {
                    if (arguments.Count > 0)
                    {
                        Console.Error.WriteLine("fatal: " + err.Message);
                        Exit(1);
                    }
                }
            }
            Exit(0);
        }