-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider JSON output for CLI #214
Comments
@ben-foster-cko do you just need the version string? Only the version is printed to stdout, as a plain string. All other messages go to stderr. If you just read stdout then the entire string is the version. |
@adamralph so just to confirm, the last line will always be the version?
|
@ben-foster-cko the version is the only line. Bear in mind that there are two output streams: stdout and stderr. You should only read stdout:
|
Also came here looking to use the CLI tool in Cake build. JSON output would be useful. An option to just output the ful version would be great too. |
@RehanSaeed as mentioned above, the full version, and only the full version, is written to stdout. You can read that, and then it is trivial to split it into its constituent parts, should you need to. |
Any link to an example how to use the cli within a cake script? Somehow I don't get this to work :-/ |
@StefanOssendorf I'm not aware of any such example. The CLI is a regular .NET SDK tool. It is invoked with |
I ended up with this code in my Cake script: var directoryBuildPropsFilePath = GetFiles("Directory.Build.props").Single().ToString();
var directoryBuildPropsDocument = System.Xml.Linq.XDocument.Load(directoryBuildPropsFilePath);
var preReleasePhase = directoryBuildPropsDocument.Descendants("MinVerDefaultPreReleasePhase").Single().Value;
string version = null;
StartProcess(
"dotnet",
new ProcessSettings()
.WithArguments(x => x
.Append("minver")
.AppendSwitch("--default-pre-release-phase", preReleasePhase))
.SetRedirectStandardOutput(true)
.SetRedirectedStandardOutputHandler( // Beware, this gets called twice, hence the null check.
output =>
{
if (output != null)
{
version = output;
}
return output;
})); I'm reading the pre-release phase from a |
That's exactly what I'm was looking for. Thank you very much :-) |
Thanks for chiming in @RehanSaeed. BTW, this is quite a bit simpler with SimpleExec: var version = Read("minver", $"--default-pre-release-phase {preReleasePhase}"); |
Hi guys, I took a stab at writing a small Cake plugin to run MinVer and parse the version: #addin "nuget:?package=Cake.MinVer&version=0.1.0"
var version = MinVer();
Task("Example")
.Does(context =>
{
context.Information($"Version: {version.Version}");
context.Information($"Major: {version.Major}");
context.Information($"Minor: {version.Minor}");
context.Information($"Patch: {version.Patch}");
context.Information($"PreRelease: {version.PreRelease}");
context.Information($"BuildMetadata: {version.BuildMetadata}");
});
RunTarget("Example"); |
That looks awesome. Would be nice if MinVer listed Cake.MinVer on it's ReadMe, for visibility. |
I'm not sure I understand the motivation. It seems to be, essentially, a .NET API for using MinVer. Why does it have a dependency on Cake? BTW, I am considering releasing the underlying MinVer library as a package, so that would also provide a .NET API. |
BTW this can be acheived today with a single line of code, using the var version = Semver.SemVersion.Parse(SimpleExec.Command.Read("minver").Trim()); |
A problem now is that Cake.Minver is a layer that needs maintenance both against Cake APIs and MinVer, will lag behind MinVer changes (which may be breaking) and may be abandoned (which has happened to other Cake plugins). @adamralph has no obligations to that plugin so my advice is caveat emptor ("buyer beware") |
@adamralph It's the other way around. It's a Cake plugin, specifically built for Cake users who are familiar with how it works and its DSL, that has a dependency on MinVer to calculate the version. |
@damianh Thanks for your support 🤷♂️ |
@augustoproiete how much value does it add over this single line? var version = Semver.SemVersion.Parse(SimpleExec.Command.Read("minver").Trim()); Is the effort worth it? |
@adamralph Yes, I think so... var version = MinVer(); Reads much better IMO, and has the added benefit of not having to take a dependency on Also,
|
Thank me later ;) |
I've been bitten by both cake and NuGet dependencies before. I think the real solution is for Cake to have something akin to SimpleExec built into it. It has some methods which are very close. Until then, the solutions above are good enough. Pick your poison. |
Why not just use SimpleExec? |
Hi,
Would you consider an option to output the version information as JSON? We need to parse the minver output in our build tool (Cake).
The text was updated successfully, but these errors were encountered: