Example #1
0
 public int Run(GitTfsCommand command, IList <string> args)
 {
     try
     {
         var runMethods          = command.GetType().GetMethods().Where(m => m.Name == "Run" && m.ReturnType == typeof(int)).Select(m => new { Method = m, Parameters = m.GetParameters() });
         var splitRunMethods     = runMethods.Where(m => m.Parameters.All(p => p.ParameterType == typeof(string)));
         var exactMatchingMethod = splitRunMethods.SingleOrDefault(m => m.Parameters.Length == args.Count);
         if (exactMatchingMethod != null)
         {
             return((int)exactMatchingMethod.Method.Invoke(command, args.ToArray()));
         }
         var defaultRunMethod = runMethods.FirstOrDefault(m => m.Parameters.Length == 1 && m.Parameters[0].ParameterType.IsAssignableFrom(args.GetType()));
         if (defaultRunMethod != null)
         {
             return((int)defaultRunMethod.Method.Invoke(command, new object[] { args }));
         }
         return(_help.ShowHelpForInvalidArguments(command));
     }
     catch (TargetInvocationException e)
     {
         if (e.InnerException is GitTfsException)
         {
             throw e.InnerException;
         }
         throw;
     }
 }
Example #2
0
 public int Main(GitTfsCommand command, IList <string> unparsedArgs)
 {
     Trace.WriteLine(_gitTfsVersionProvider.GetVersionString());
     if (_globals.ShowHelp)
     {
         return(_help.ShowHelp(command));
     }
     else if (_globals.ShowVersion)
     {
         Trace.TraceInformation(_gitTfsVersionProvider.GetVersionString());
         Trace.TraceInformation(GitTfsConstants.MessageForceVersion);
         return(GitTfsExitCodes.OK);
     }
     else
     {
         try
         {
             return(_runner.Run(command, unparsedArgs));
         }
         finally
         {
             _container.GetInstance <Janitor>().Dispose();
         }
     }
 }
Example #3
0
 public int Main(GitTfsCommand command, IList<string> unparsedArgs)
 {
     Trace.WriteLine(_gitTfsVersionProvider.GetVersionString());
     if(_globals.ShowHelp)
     {
         return _help.ShowHelp(command);
     }
     else if(_globals.ShowVersion)
     {
         _container.GetInstance<TextWriter>().WriteLine(_gitTfsVersionProvider.GetVersionString());
         _container.GetInstance<TextWriter>().WriteLine(GitTfsConstants.MessageForceVersion);
         return GitTfsExitCodes.OK;
     }
     else
     {
         try
         {
             return _runner.Run(command, unparsedArgs);
         }
         finally
         {
             _container.GetInstance<Janitor>().Dispose();
         }
     }
 }
Example #4
0
 public IList <string> ParseOptions(GitTfsCommand command, IList <string> args)
 {
     foreach (var parseHelper in command.GetOptionParseHelpers(_container))
     {
         var parser = new Parser(parseHelper);
         args = parser.Parse(args.ToArray());
     }
     return(args);
 }
Example #5
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
                return Run();

            output.WriteLine("Usage: git-tfs " + GetCommandUsage(command));
            command.GetAllOptions(_container).WriteOptionDescriptions(output);

            return GitTfsExitCodes.Help;
        }
Example #6
0
        private string GetCommandUsage(GitTfsCommand command)
        {
            var descriptionAttribute =
                command.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as
                DescriptionAttribute;
            var commandName = GetCommandName(command);

            return((descriptionAttribute != null)
                       ? descriptionAttribute.Description
                       : commandName + " [options]");
        }
Example #7
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
                return Run();

            output.WriteLine("Usage: git-tfs " + GetCommandUsage(command));
            command.GetAllOptions(_container).WriteOptionDescriptions(output);

            output.WriteLine("\nFind more help in our online help : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/" + GetCommandName(command)+".md");

            return GitTfsExitCodes.Help;
        }
Example #8
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
            {
                return(Run());
            }

            output.WriteLine("Usage: git-tfs " + GetCommandUsage(command));
            command.GetAllOptions(_container).WriteOptionDescriptions(output);

            return(GitTfsExitCodes.Help);
        }
Example #9
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
            {
                return(Run());
            }

            output.WriteLine("Usage: git-tfs " + GetCommandUsage(command));
            command.GetAllOptions(_container).WriteOptionDescriptions(output);

            output.WriteLine("\nFind more help in our online help : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/" + GetCommandName(command) + ".md");

            return(GitTfsExitCodes.Help);
        }
Example #10
0
        public static IEnumerable <IOptionResults> GetOptionParseHelpers(this GitTfsCommand command, IContainer container)
        {
            yield return(new PropertyFieldParserHelper(container.GetInstance <Globals>()));

            yield return(new PropertyFieldParserHelper(command));

            if (command.ExtraOptions != null)
            {
                foreach (var parseHelper in command.ExtraOptions)
                {
                    yield return(parseHelper);
                }
            }
        }
Example #11
0
 public int Main(GitTfsCommand command, IList <string> unparsedArgs)
 {
     Trace.WriteLine(_gitTfsVersionProvider.GetVersionString());
     if (_globals.ShowHelp)
     {
         return(_help.ShowHelp(command));
     }
     else if (_globals.ShowVersion)
     {
         _container.GetInstance <TextWriter>().WriteLine(_gitTfsVersionProvider.GetVersionString());
         return(GitTfsExitCodes.OK);
     }
     else
     {
         return(_runner.Run(command, unparsedArgs));
     }
 }
Example #12
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
            {
                return(Run());
            }

            Trace.TraceInformation("Usage: git-tfs " + GetCommandUsage(command));
            var writer = new StringWriter();

            command.GetAllOptions(_container).WriteOptionDescriptions(writer);
            Trace.TraceInformation(writer.ToString());

            Trace.TraceInformation("\nFind more help in our online help : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/" + GetCommandName(command) + ".md");

            return(GitTfsExitCodes.Help);
        }
Example #13
0
 public int Main(GitTfsCommand command, IList<string> unparsedArgs)
 {
     Trace.WriteLine(_gitTfsVersionProvider.GetVersionString());
     if(_globals.ShowHelp)
     {
         return _help.ShowHelp(command);
     }
     else if(_globals.ShowVersion)
     {
         _container.GetInstance<TextWriter>().WriteLine(_gitTfsVersionProvider.GetVersionString());
         return GitTfsExitCodes.OK;
     }
     else
     {
         return _runner.Run(command, unparsedArgs);
     }
 }
Example #14
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
            {
                return(Run());
            }

            var usage = new UsageBuilder();

            usage.BeginSection("where options are:");
            foreach (var parseHelper in command.GetOptionParseHelpers(_container))
            {
                usage.AddOptions(parseHelper);
            }
            usage.EndSection();
            output.WriteLine("Usage: git-tfs " + GetCommandUsage(command));
            usage.ToText(output, OptStyle.Unix, true);
            return(GitTfsExitCodes.Help);
        }
Example #15
0
        public void Main(GitTfsCommand command, IList <string> unparsedArgs)
        {
            var globals = _container.GetInstance <Globals>();

            if (globals.ShowHelp)
            {
                Environment.ExitCode = _help.ShowHelp(command);
            }
            else if (globals.ShowVersion)
            {
                _container.GetInstance <TextWriter>().WriteLine(MakeVersionString());
                Environment.ExitCode = GitTfsExitCodes.OK;
            }
            else
            {
                Environment.ExitCode = _runner.Run(command, unparsedArgs);
                //PostFetchCheckout();
            }
        }
Example #16
0
 public int Run(GitTfsCommand command, IList<string> args)
 {
     try
     {
         var runMethods = command.GetType().GetMethods().Where(m => m.Name == "Run" && m.ReturnType == typeof(int)).Select(m => new { Method = m, Parameters = m.GetParameters() });
         var splitRunMethods = runMethods.Where(m => m.Parameters.All(p => p.ParameterType == typeof(string)));
         var exactMatchingMethod = splitRunMethods.SingleOrDefault(m => m.Parameters.Length == args.Count);
         if (exactMatchingMethod != null)
             return (int)exactMatchingMethod.Method.Invoke(command, args.ToArray());
         var defaultRunMethod = runMethods.FirstOrDefault(m => m.Parameters.Length == 1 && m.Parameters[0].ParameterType.IsAssignableFrom(args.GetType()));
         if (defaultRunMethod != null)
             return (int)defaultRunMethod.Method.Invoke(command, new object[] { args });
         return _help.ShowHelpForInvalidArguments(command);
     }
     catch (TargetInvocationException e)
     {
         if (e.InnerException is GitTfsException)
             throw e.InnerException;
         throw;
     }
 }
Example #17
0
 public static IEnumerable <IOptionResults> MakeNestedOptionResults(this GitTfsCommand command, params object[] optionsObjectsOrCommands)
 {
     foreach (var obj in optionsObjectsOrCommands)
     {
         if (obj is GitTfsCommand)
         {
             foreach (var option in ((GitTfsCommand)obj).ExtraOptions)
             {
                 yield return(option);
             }
             yield return(new PropertyFieldParserHelper(obj));
         }
         else if (obj is IOptionResults)
         {
             yield return((IOptionResults)obj);
         }
         else
         {
             yield return(new PropertyFieldParserHelper(obj));
         }
     }
 }
Example #18
0
 public IList<string> ParseOptions(GitTfsCommand command, IList<string> args)
 {
     foreach(var parseHelper in command.GetOptionParseHelpers())
     {
         var parser = new Parser(parseHelper);
         args = parser.Parse(args.ToArray());
     }
     return args;
 }
Example #19
0
 public void Main(GitTfsCommand command, IList<string> unparsedArgs)
 {
     var globals = ObjectFactory.GetInstance<Globals>();
     if(globals.ShowHelp)
     {
         Environment.ExitCode = Help.ShowHelp(command);
     }
     else if(globals.ShowVersion)
     {
         ObjectFactory.GetInstance<TextWriter>().WriteLine(MakeVersionString());
         Environment.ExitCode = GitTfsExitCodes.OK;
     }
     else
     {
         Environment.ExitCode = command.Run(unparsedArgs);
         //PostFetchCheckout();
     }
 }
Example #20
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
                return Run();

            var usage = new UsageBuilder();
            usage.BeginSection("where options are:");
            foreach (var parseHelper in command.GetOptionParseHelpers(_container))
                usage.AddOptions(parseHelper);
            usage.EndSection();
            output.WriteLine("Usage: git-tfs " + GetCommandUsage(command));
            usage.ToText(output, OptStyle.Unix, true);
            return GitTfsExitCodes.Help;
        }
Example #21
0
 public int ShowHelpForInvalidArguments(GitTfsCommand command)
 {
     ShowHelp(command);
     return GitTfsExitCodes.InvalidArguments;
 }
Example #22
0
 public int ShowHelp(GitTfsCommand command)
 {
     return _container.GetInstance<Help>().Run(command);
 }
Example #23
0
 private string GetCommandUsage(GitTfsCommand command)
 {
     var descriptionAttribute =
         command.GetType().GetCustomAttributes(typeof (DescriptionAttribute), false).FirstOrDefault() as
         DescriptionAttribute;
     var commandName = GetCommandName(command);
     return (descriptionAttribute != null)
                ? descriptionAttribute.Description
                : commandName + " [options]";
 }
Example #24
0
 private string GetCommandName(GitTfsCommand command)
 {
     return (from instance in GetCommandInstances()
             where instance.ConcreteType == command.GetType()
             select instance.Name).Single();
 }
Example #25
0
        /// <summary>
        /// Shows help for a specific command.
        /// </summary>
        public int Run(GitTfsCommand command)
        {
            if (command is Help)
                return Run();

            Trace.TraceInformation("Usage: git-tfs " + GetCommandUsage(command));
            var writer = new StringWriter();
            command.GetAllOptions(_container).WriteOptionDescriptions(writer);
            Trace.TraceInformation(writer.ToString());

            Trace.TraceInformation("\nFind more help in our online help : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/" + GetCommandName(command) + ".md");

            return GitTfsExitCodes.Help;
        }
Example #26
0
 public IList<string> ParseOptions(GitTfsCommand command, IList<string> args)
 {
     return command.GetAllOptions(_container).Parse(args);
 }
Example #27
0
 public bool RequiresValidGitRepository(GitTfsCommand command)
 {
     return(!command.GetType().GetCustomAttributes(typeof(RequiresValidGitRepositoryAttribute), false).IsEmpty());
 }
Example #28
0
 public void Main(GitTfsCommand command, IList<string> unparsedArgs)
 {
     Trace.WriteLine(_gitTfsVersionProvider.GetVersionString());
     if(_globals.ShowHelp)
     {
         Environment.ExitCode = _help.ShowHelp(command);
     }
     else if(_globals.ShowVersion)
     {
         _container.GetInstance<TextWriter>().WriteLine(_gitTfsVersionProvider.GetVersionString());
         Environment.ExitCode = GitTfsExitCodes.OK;
     }
     else
     {
         Environment.ExitCode = _runner.Run(command, unparsedArgs);
         //PostFetchCheckout();
     }
 }
Example #29
0
 private string GetCommandName(GitTfsCommand command)
 {
     return((from instance in GetCommandInstances()
             where instance.ConcreteType == command.GetType()
             select instance.Name).Single());
 }
Example #30
0
 public IList <string> ParseOptions(GitTfsCommand command, IList <string> args)
 {
     return(command.GetAllOptions(_container).Parse(args));
 }
Example #31
0
 public int ShowHelp(GitTfsCommand command)
 {
     return(_container.GetInstance <Help>().Run(command));
 }
Example #32
0
 public static OptionSet GetAllOptions(this GitTfsCommand command, IContainer container)
 {
     return(container.GetInstance <Globals>().OptionSet.Merge(command.OptionSet));
 }
Example #33
0
 public int ShowHelpForInvalidArguments(GitTfsCommand command)
 {
     ShowHelp(command);
     return(GitTfsExitCodes.InvalidArguments);
 }
Example #34
0
 public bool RequiresValidGitRepository(GitTfsCommand command)
 {
     return ! command.GetType().GetCustomAttributes(typeof (RequiresValidGitRepositoryAttribute), false).IsEmpty();
 }
Example #35
0
 public Clone(Globals globals)
 {
     fetch = ObjectFactory.GetNamedInstance<GitTfsCommand>("fetch");
     init = ObjectFactory.GetNamedInstance<GitTfsCommand>("init");
     this.globals = globals;
 }