Example #1
0
        /// <summary>
        /// Run an array of commands, one after the other, then finally run OnComplete when process completes
        /// </summary>
        /// <param name="commands"></param>
        /// <param name="onComplete"></param>
        public static void RunCommands(string[] commands, Action <CommandOutput[]> onComplete)
        {
            CommandOutput[] outputs = new CommandOutput[commands.Length];

            //TODO: This super hacky loop relies on the fact that RunCommand is NOT async!!!
            //BAD
            for (int i = 0; i < commands.Length; i++)
            {
                RunCommand(commands[i], (output) => { outputs[i] = output; });
            }

            onComplete(outputs);
        }
Example #2
0
        /// <summary>
        /// Run a git command, running onComplete when process completes.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="onComplete"></param>
        /// <param name="onError"></param>
        public static void RunCommand(string command, Action <CommandOutput> onComplete)
        {
            string outputData = null;
            string errorData  = null;

            if (GitGudSettings.GetBool("debug"))
            {
                UnityEngine.Debug.Log("Running command " + command);
            }

            RunCommandInternal(command,
                               (output) => {
                //Output stream
                if (output != null)
                {
                    if (outputData == null)
                    {
                        outputData = output;
                    }
                    else
                    {
                        outputData += "\n" + output;
                    }
                }
            },

                               (error) => {
                //Error stream
                if (error != null)
                {
                    //Special case: Stop line endings error
                    if (error.Contains("LF will be replaced by CRLF"))
                    {
                        return;
                    }

                    if (error.Contains("The file will have its original line endings in your working directory"))
                    {
                        return;
                    }

                    if (errorData == null)
                    {
                        errorData = error;
                    }
                    else
                    {
                        errorData += "\n" + error;
                    }
                }
            },
                               () =>
            {
                //Debugging
                if (GitGudSettings.GetBool("debug") && outputData != null)
                {
                    UnityEngine.Debug.Log("<color=blue>Output:</color>" + outputData);
                }

                if (GitGudSettings.GetBool("debug") && errorData != null)
                {
                    UnityEngine.Debug.Log("<color=red>Error:</color>" + errorData);
                }

                CommandOutput output = new CommandOutput(outputData, errorData);
                if (onComplete != null)
                {
                    onComplete(output);
                }
            }
                               );
        }