diff --git a/README.md b/README.md index 75c8437..c04c2cc 100644 --- a/README.md +++ b/README.md @@ -22,17 +22,20 @@ Usage: PaketChain [options] Options: -d|--dir The path to a root of a repository, defaults to current directory if not provided (Note: should be in quotes) - -upt|--update-paket-tool update the paket tool - -u|--update Include a paket update + -u|--update Run a paket update -ua|--update-args Args to pass to paket update (Note: should be in quotes) - -co|--clean-obj Clean obj folders to force a full update - -i|--install Include a paket install + -i|--install Run a paket install -ia|--install-args Args to pass to paket install (Note: should be in quotes) - -r|--reinstall Delete the lock file and create from scratch - -s|--simplify Include a paket simplify + -r|--restore Run a paket restore + -ra|--restore-args Args to pass to paket restore (Note: should be in quotes) + -s|--simplify Run a paket simplify -sa|--simplify-args Args to pass to paket simplify (Note: should be in quotes) + -ri|--reinstall Delete the lock file and create from scratch -so|--sort Sort paket files alphabetically -cc|--clear-cache Clear caches before running + -gc|--git-clean Run git clean + -co|--clean-obj Clean obj folders to force a full update + -upt|--update-paket-tool update the paket tool -np|--no-prompt Never prompt user input -v|--verbose Verbose logging -?|-h|--help Show help information diff --git a/src/PaketChain/ConsoleHelper.cs b/src/PaketChain/ConsoleHelper.cs index 147c3a1..c2493bb 100644 --- a/src/PaketChain/ConsoleHelper.cs +++ b/src/PaketChain/ConsoleHelper.cs @@ -127,5 +127,42 @@ public static void RunPaketCommand(string rootDir, string paketExePath, PaketTyp throw new Exception($"Paket exit code: {process.ExitCode}"); } } + + public static void RunGitCommand(string rootDir, string command, string args, CancellationToken cancellationToken) + { + var processInfo = new ProcessStartInfo + { + WorkingDirectory = rootDir, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true, + FileName = "git", + Arguments = $"{command} {args ?? string.Empty}".Trim() + }; + + var process = new Process + { + StartInfo = processInfo, + EnableRaisingEvents = true + }; + + process.OutputDataReceived += (sender, eventArgs) => { Console.WriteLine(eventArgs.Data); }; + process.ErrorDataReceived += (sender, eventArgs) => { Console.WriteLine(eventArgs.Data); }; + + cancellationToken.Register(() => process.Kill(true)); + + Console.WriteLine($"Running: {processInfo.FileName} {processInfo.Arguments}"); + Console.WriteLine(""); + process.Start(); + process.BeginOutputReadLine(); + process.WaitForExit(); + process.CancelOutputRead(); + + if (process.ExitCode < 0) + { + throw new Exception($"Git exit code: {process.ExitCode}"); + } + } } } diff --git a/src/PaketChain/Runner.cs b/src/PaketChain/Runner.cs index 67a4cf6..0f68008 100644 --- a/src/PaketChain/Runner.cs +++ b/src/PaketChain/Runner.cs @@ -109,13 +109,28 @@ private static int Run(RunnerArgs runnerArgs, CancellationToken cancellationToke if (cancellationToken.IsCancellationRequested) return -2; } - if (runnerArgs.CleanObj) + if (runnerArgs.GitClean) { - FileSystem.CleanObjFiles(rootDir); + ConsoleHelper.RunGitCommand(rootDir, "clean", "-dfx", cancellationToken); Console.WriteLine("-----------------------------------------------------"); if (cancellationToken.IsCancellationRequested) return -2; } + if (runnerArgs.CleanObj) + { + if (runnerArgs.GitClean) + { + Console.WriteLine("Skipping Clean Objects as Git clean run"); + Console.WriteLine("-----------------------------------------------------"); + } + else + { + FileSystem.CleanObjFiles(rootDir); + Console.WriteLine("-----------------------------------------------------"); + if (cancellationToken.IsCancellationRequested) return -2; + } + } + if (runnerArgs.Reinstall) { Console.WriteLine("Deleting paket.lock file"); @@ -129,11 +144,14 @@ private static int Run(RunnerArgs runnerArgs, CancellationToken cancellationToke if (runnerArgs.Reinstall) { Console.WriteLine("Skipping Update as reinstall install newest versions"); + Console.WriteLine("-----------------------------------------------------"); + } + else + { + ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "update", runnerArgs.UpdateArgs, cancellationToken); + Console.WriteLine("-----------------------------------------------------"); + if (cancellationToken.IsCancellationRequested) return -2; } - - ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "update", runnerArgs.UpdateArgs, cancellationToken); - Console.WriteLine("-----------------------------------------------------"); - if (cancellationToken.IsCancellationRequested) return -2; } if (runnerArgs.Simplify) @@ -150,6 +168,21 @@ private static int Run(RunnerArgs runnerArgs, CancellationToken cancellationToke if (cancellationToken.IsCancellationRequested) return -2; } + if (runnerArgs.Restore) + { + if (runnerArgs.Install || runnerArgs.Reinstall || runnerArgs.Simplify) + { + Console.WriteLine("Skipping Restore as already installed"); + Console.WriteLine("-----------------------------------------------------"); + } + else + { + ConsoleHelper.RunPaketCommand(rootDir, paketPath, toolType, "restore", runnerArgs.RestoreArgs, cancellationToken); + Console.WriteLine("-----------------------------------------------------"); + if (cancellationToken.IsCancellationRequested) return -2; + } + } + return 0; } } diff --git a/src/PaketChain/RunnerArgs.cs b/src/PaketChain/RunnerArgs.cs index 3613c00..3fcdeeb 100644 --- a/src/PaketChain/RunnerArgs.cs +++ b/src/PaketChain/RunnerArgs.cs @@ -11,39 +11,48 @@ internal class RunnerArgs [Option("-d|--dir ", "The path to a root of a repository, defaults to current directory if not provided (Note: should be in quotes)", CommandOptionType.SingleValue)] public string Directory { get; } - [Option("-upt|--update-paket-tool", "update the paket tool", CommandOptionType.NoValue)] - public bool UpdateTool { get; } - - [Option("-u|--update", "Include a paket update", CommandOptionType.NoValue)] + [Option("-u|--update", "Run a paket update", CommandOptionType.NoValue)] public bool Update { get; } [Option("-ua|--update-args ", "Args to pass to paket update (Note: should be in quotes)", CommandOptionType.SingleValue)] public string UpdateArgs { get; } - [Option("-co|--clean-obj", "Clean obj folders to force a full update", CommandOptionType.NoValue)] - public bool CleanObj { get; } - - [Option("-i|--install", "Include a paket install", CommandOptionType.NoValue)] + [Option("-i|--install", "Run a paket install", CommandOptionType.NoValue)] public bool Install { get; } [Option("-ia|--install-args ", "Args to pass to paket install (Note: should be in quotes)", CommandOptionType.SingleValue)] public string InstallArgs { get; } - [Option("-r|--reinstall", "Delete the lock file and create from scratch", CommandOptionType.NoValue)] - public bool Reinstall { get; } + [Option("-r|--restore", "Run a paket restore", CommandOptionType.NoValue)] + public bool Restore { get; } - [Option("-s|--simplify", "Include a paket simplify", CommandOptionType.NoValue)] + [Option("-ra|--restore-args ", "Args to pass to paket restore (Note: should be in quotes)", CommandOptionType.SingleValue)] + public string RestoreArgs { get; } + + [Option("-s|--simplify", "Run a paket simplify", CommandOptionType.NoValue)] public bool Simplify { get; } [Option("-sa|--simplify-args ", "Args to pass to paket simplify (Note: should be in quotes)", CommandOptionType.SingleValue)] public string SimplifyArgs { get; } + [Option("-ri|--reinstall", "Delete the lock file and create from scratch", CommandOptionType.NoValue)] + public bool Reinstall { get; } + [Option("-so|--sort", "Sort paket files alphabetically", CommandOptionType.NoValue)] public bool Sort { get; } [Option("-cc|--clear-cache", "Clear caches before running", CommandOptionType.NoValue)] public bool ClearCache { get; } + [Option("-gc|--git-clean", "Run git clean", CommandOptionType.NoValue)] + public bool GitClean { get; } + + [Option("-co|--clean-obj", "Clean obj folders to force a full update", CommandOptionType.NoValue)] + public bool CleanObj { get; } + + [Option("-upt|--update-paket-tool", "update the paket tool", CommandOptionType.NoValue)] + public bool UpdateTool { get; } + [Option("-np|--no-prompt", "Never prompt user input", CommandOptionType.NoValue)] public bool NoPrompt { get; }