public ParsedCommandLineParameters ParseCommandLineParameters(string[] args)
        {
            var result             = new ParsedCommandLineParameters();
            var remainingArguments = new List <string>();

            for (int i = 0; i < args.Length; i++)
            {
                var arg = args[i];

                if (arg.StartsWith("/"))
                {
                    ParsedCommandLineParameter parameter = ParseParameter(args, ref i);

                    if (parameter != null)
                    {
                        result.Parameters.Add(parameter);
                    }
                }
                else
                {
                    remainingArguments.Add(arg);
                }
            }

            result.RemainingArguments = remainingArguments.ToArray();

            return(result);
        }
 public void ParseCommandLine(ParsedCommandLineParameters parsedParameters, IBounce bounce)
 {
     parsedParameters.IfParameterDo(LogLevelParameter, loglevel => bounce.LogOptions.LogLevel = ParseLogLevel(loglevel));
     parsedParameters.IfParameterDo(CommandOutputParameter, commandOutput => bounce.LogOptions.CommandOutput = ParseBoolOption(commandOutput));
     parsedParameters.IfParameterDo(LogFormatParameter, logformat => bounce.LogFactory = GetLogFactoryByName(logformat));
     parsedParameters.IfParameterDo(DescribeTasksParameter, descTasks => bounce.LogOptions.DescribeTasks = ParseBoolOption(descTasks));
     parsedParameters.IfParameterDo(LogFileParameter, logFileName =>
     {
         var textWriter           = File.AppendText(logFileName);
         textWriter.AutoFlush     = true;
         bounce.LogOptions.StdOut = textWriter;
         bounce.LogOptions.StdErr = textWriter;
     });
 }
 public void ParseCommandLine(ParsedCommandLineParameters parsedParameters, IBounce bounce)
 {
     parsedParameters.IfParameterDo(LogLevelParameter, loglevel => bounce.LogOptions.LogLevel = ParseLogLevel(loglevel));
     parsedParameters.IfParameterDo(CommandOutputParameter, commandOutput => bounce.LogOptions.CommandOutput = ParseBoolOption(commandOutput));
     parsedParameters.IfParameterDo(LogFormatParameter, logformat => bounce.LogFactory = GetLogFactoryByName(logformat));
     parsedParameters.IfParameterDo(DescribeTasksParameter, descTasks => bounce.LogOptions.DescribeTasks = ParseBoolOption(descTasks));
     parsedParameters.IfParameterDo(LogFileParameter, logFileName =>
                                               {
                                                   var textWriter = File.AppendText(logFileName);
                                                   textWriter.AutoFlush = true;
                                                   bounce.LogOptions.StdOut = textWriter;
                                                   bounce.LogOptions.StdErr = textWriter;
                                               });
 }
Exemple #4
0
        public void Run(string[] args, MethodInfo getTargetsMethod)
        {
            TargetsPath = new Uri(getTargetsMethod.Module.Assembly.CodeBase).LocalPath;

            var parameters = new CommandLineParameters();

            try {
                IDictionary <string, IObsoleteTask> targets = GetTargetsFromAssembly(getTargetsMethod, parameters);

                ParsedCommandLineParameters parsedParameters = ParseCommandLineArguments(args);

                string[] buildArguments = parsedParameters.RemainingArguments;

                CommandAndTargets commandAndTargets = CommandAndTargetParser.ParseCommandAndTargetNames(buildArguments, targets);

                if (commandAndTargets.Targets.Count() >= 1)
                {
                    var bounce = new Bounce();

                    InterpretParameters(parameters, parsedParameters, bounce);

                    try
                    {
                        EnsureAllRequiredParametersAreSet(parameters, commandAndTargets.Targets);

                        BuildTargets(bounce, commandAndTargets);
                    }
                    catch (BounceException ce)
                    {
                        ce.Explain(bounce.LogOptions.StdErr);
                        Environment.Exit(1);
                    }
                }
                else
                {
                    System.Console.WriteLine("usage: bounce build|clean target-name");
                    PrintAvailableTargets(targets);
                    Environment.Exit(1);
                }
            } catch (BounceException ce) {
                ce.Explain(System.Console.Error);
                Environment.Exit(1);
            }
        }
Exemple #5
0
 private void InterpretParameters(ICommandLineParameters parameters, ParsedCommandLineParameters parsedParameters, Bounce bounce)
 {
     LogOptionCommandLineTranslator.ParseCommandLine(parsedParameters, bounce);
     bounce.ParametersGiven = parameters.ParseCommandLineArguments(parsedParameters.Parameters);
 }
Exemple #6
0
 private void InterpretParameters(ICommandLineParameters parameters, ParsedCommandLineParameters parsedParameters, Bounce bounce)
 {
     LogOptionCommandLineTranslator.ParseCommandLine(parsedParameters, bounce);
     bounce.ParametersGiven = parameters.ParseCommandLineArguments(parsedParameters.Parameters);
 }