Skip to content

Commit

Permalink
Add restore & gitclean support
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Jan 29, 2020
1 parent 086805e commit d5f2b79
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 23 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ Usage: PaketChain [options]
Options:
-d|--dir <PATH> The path to a root of a repository, defaults to current directory if not provided (Note: <PATH> 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> Args to pass to paket update (Note: <ARGS> 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> Args to pass to paket install (Note: <ARGS> 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> Args to pass to paket restore (Note: <ARGS> should be in quotes)
-s|--simplify Run a paket simplify
-sa|--simplify-args <ARGS> Args to pass to paket simplify (Note: <ARGS> 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
Expand Down
37 changes: 37 additions & 0 deletions src/PaketChain/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
}
45 changes: 39 additions & 6 deletions src/PaketChain/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
Expand All @@ -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;
}
}
Expand Down
31 changes: 20 additions & 11 deletions src/PaketChain/RunnerArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,48 @@ internal class RunnerArgs
[Option("-d|--dir <PATH>", "The path to a root of a repository, defaults to current directory if not provided (Note: <PATH> 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>", "Args to pass to paket update (Note: <ARGS> 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>", "Args to pass to paket install (Note: <ARGS> 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>", "Args to pass to paket restore (Note: <ARGS> 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>", "Args to pass to paket simplify (Note: <ARGS> 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; }

Expand Down

0 comments on commit d5f2b79

Please sign in to comment.