Skip to content
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

GH2886/2904: Bring Frosting up to speed #2946

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class BuildParameters
Packages = BuildPackages.GetPackages(
Paths.Directories.NuGetRoot,
Version.SemVersion,
new [] {
new [] {
"Cake",
"Cake.Core",
"Cake.Common",
Expand All @@ -114,7 +114,8 @@ public class BuildParameters
"Cake.NuGet",
"Cake.Tool",
"Cake.Frosting",
"Cake.Frosting.Template"
"Cake.Frosting.Template",
"Cake.Cli"
},
new [] { "cake.portable" });

Expand Down
25 changes: 25 additions & 0 deletions src/Cake.Cli/Cake.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Cli</AssemblyName>
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<!-- Package specific metadata -->
<PropertyGroup>
<Description>The Cake CLI library.</Description>
</PropertyGroup>

<!-- Import shared functionality -->
<Import Project="..\Shared.msbuild" />
<ItemGroup>
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.1.0" />
<PackageReference Include="Spectre.Cli" Version="0.46.0" />
</ItemGroup>
</Project>
79 changes: 79 additions & 0 deletions src/Cake.Cli/Features/InfoFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Cake.Core;

namespace Cake.Cli
{
/// <summary>
/// Represents a feature that writes information about Cake to the console.
/// </summary>
public interface ICakeInfoFeature
{
/// <summary>
/// Runs the feature.
/// </summary>
/// <param name="console">The console to write to.</param>
void Run(IConsole console);
}

/// <summary>
/// Writes information about Cake to the console.
/// </summary>
public sealed class InfoFeature : ICakeInfoFeature
{
private readonly IVersionResolver _resolver;

/// <summary>
/// Initializes a new instance of the <see cref="InfoFeature"/> class.
/// </summary>
/// <param name="resolver">The version resolver.</param>
public InfoFeature(IVersionResolver resolver)
{
_resolver = resolver;
}

/// <inheritdoc/>
public void Run(IConsole console)
{
var version = _resolver.GetVersion();
var product = _resolver.GetProductVersion();

console.WriteLine();
console.WriteLine(@" +## #;;'");
console.WriteLine(@" #;;# .+;;;;+,");
console.WriteLine(@" '+;;#;,+';;;;;'#.");
console.WriteLine(@" ++'''';;;;;;;;;;# ;#;");
console.WriteLine(@" ##';;;;++'+#;;;;;'. `#:");
console.WriteLine(@" ;# '+'';;;;;;;;;'#` #.");
console.WriteLine(@" `#, .'++;;;;;':..........#");
console.WriteLine(@" '+ `.........';;;;':.........#");
console.WriteLine(@" #..................+;;;;;':........#");
console.WriteLine(@" #..................#';;;;;'+''''''.#");
console.WriteLine(@" #.......,:;''''''''##';;;;;'+'''''#,");
console.WriteLine(@" #''''''''''''''''''###';;;;;;+''''#");
console.WriteLine(@" #''''''''''''''''''####';;;;;;#'''#");
console.WriteLine(@" #''''''''''''''''''#####';;;;;;#''#");
console.WriteLine(@" #''''''''''''''''''######';;;;;;#'#");
console.WriteLine(@" #''''''''''''''''''#######';;;;;;##");
console.WriteLine(@" #''''''''''''''''''########';;;;;;#");
console.WriteLine(@" #''''''''''''++####+;#######';;;;;;#");
console.WriteLine(@" #+####':,` ,#####';;;;;;'");
console.WriteLine(@" +##'''''+.");

console.ForegroundColor = System.ConsoleColor.Yellow;
console.WriteLine(@" ___ _ ___ _ _ _ ");
console.WriteLine(@" / __\__ _| | _____ / __\_ _(_) | __| |");
console.WriteLine(@" / / / _` | |/ / _ \/__\// | | | | |/ _` |");
console.WriteLine(@"/ /___ (_| | < __/ \/ \ |_| | | | (_| |");
console.WriteLine(@"\____/\__,_|_|\_\___\_____/\__,_|_|_|\__,_|");
console.ResetColor();

console.WriteLine();
console.WriteLine(@"Version: {0}", version);
console.WriteLine(@"Details: {0}", string.Join("\n ", product.Split('/')));
console.WriteLine();
}
}
}
49 changes: 49 additions & 0 deletions src/Cake.Cli/Features/VersionFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Cake.Core;

namespace Cake.Cli
{
/// <summary>
/// Represents a feature that writes the Cake version to the console.
/// </summary>
public interface ICakeVersionFeature
{
/// <summary>
/// Writes the Cake version to the console.
/// </summary>
/// <param name="console">The console to write to.</param>
void Run(IConsole console);
}

/// <summary>
/// Writes the Cake version to the console.
/// </summary>
public sealed class VersionFeature : ICakeVersionFeature
{
private readonly IVersionResolver _resolver;

/// <summary>
/// Initializes a new instance of the <see cref="VersionFeature"/> class.
/// </summary>
/// <param name="resolver">The version resolver.</param>
public VersionFeature(IVersionResolver resolver)
{
_resolver = resolver;
}

/// <inheritdoc/>
public void Run(IConsole console)
{
if (console is null)
{
throw new ArgumentNullException(nameof(console));
}

console.WriteLine(_resolver.GetVersion());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Reflection;

namespace Cake.Features.Introspection
namespace Cake.Cli
{
/// <summary>
/// Represents a version resolver.
/// </summary>
public interface IVersionResolver
{
/// <summary>
/// Gets the version.
/// </summary>
/// <returns>The version.</returns>
string GetVersion();

/// <summary>
/// Gets the product version.
/// </summary>
/// <returns>The product version.</returns>
string GetProductVersion();
}

/// <summary>
/// The Cake version resolver.
/// </summary>
public sealed class VersionResolver : IVersionResolver
{
/// <inheritdoc/>
public string GetVersion()
{
var assembly = typeof(Program).Assembly;
var assembly = Assembly.GetEntryAssembly();
var version = FileVersionInfo.GetVersionInfo(assembly.Location).Comments;

if (string.IsNullOrWhiteSpace(version))
Expand All @@ -27,9 +44,10 @@ public string GetVersion()
return version;
}

/// <inheritdoc/>
public string GetProductVersion()
{
var assembly = typeof(Program).Assembly;
var assembly = Assembly.GetEntryAssembly();
var version = FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;

if (string.IsNullOrWhiteSpace(version))
Expand Down
82 changes: 82 additions & 0 deletions src/Cake.Cli/Hosts/BuildScriptHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.Scripting;

namespace Cake.Cli
{
/// <summary>
/// The script host used to execute Cake scripts.
/// </summary>
public sealed class BuildScriptHost : BuildScriptHost<ICakeContext>
{
/// <summary>
/// Initializes a new instance of the <see cref="BuildScriptHost"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="executionStrategy">The execution strategy.</param>
/// <param name="context">The context.</param>
/// <param name="reportPrinter">The report printer.</param>
/// <param name="log">The log.</param>
public BuildScriptHost(
ICakeEngine engine,
IExecutionStrategy executionStrategy,
ICakeContext context,
ICakeReportPrinter reportPrinter,
ICakeLog log) : base(engine, executionStrategy, context, reportPrinter, log)
{
}
}

/// <summary>
/// The script host used to execute Cake scripts.
/// </summary>
/// <typeparam name="TContext">The context type.</typeparam>
public class BuildScriptHost<TContext> : ScriptHost
where TContext : ICakeContext
{
private readonly ICakeReportPrinter _reportPrinter;
private readonly ICakeLog _log;
private readonly IExecutionStrategy _executionStrategy;
private readonly TContext _context;

/// <summary>
/// Initializes a new instance of the <see cref="BuildScriptHost{TContext}"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="executionStrategy">The execution strategy.</param>
/// <param name="context">The context.</param>
/// <param name="reportPrinter">The report printer.</param>
/// <param name="log">The log.</param>
public BuildScriptHost(
ICakeEngine engine,
IExecutionStrategy executionStrategy,
TContext context,
ICakeReportPrinter reportPrinter,
ICakeLog log) : base(engine, context)
{
_executionStrategy = executionStrategy;
_context = context;
_reportPrinter = reportPrinter;
_log = log;
}

/// <inheritdoc/>
public override async Task<CakeReport> RunTargetAsync(string target)
{
Settings.SetTarget(target);

var report = await Engine.RunTargetAsync(_context, _executionStrategy, Settings).ConfigureAwait(false);
if (report != null && !report.IsEmpty)
{
_reportPrinter.Write(report);
}

return report;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using Cake.Core;
using Cake.Core.Scripting;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
/// <summary>
/// The script host used for showing task descriptions.
/// </summary>
public sealed class DescriptionScriptHost : ScriptHost
public class DescriptionScriptHost : ScriptHost
{
private readonly IConsole _console;
private readonly Dictionary<string, string> _descriptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Cake.Core;
using Cake.Core.Diagnostics;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
internal sealed class DryRunExecutionStrategy : IExecutionStrategy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,41 @@
using Cake.Core.Diagnostics;
using Cake.Core.Scripting;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
/// <summary>
/// The script host used to dry run Cake scripts.
/// </summary>
public sealed class DryRunScriptHost : ScriptHost
public sealed class DryRunScriptHost : DryRunScriptHost<ICakeContext>
{
private readonly ICakeLog _log;

/// <summary>
/// Initializes a new instance of the <see cref="DryRunScriptHost"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="context">The context.</param>
/// <param name="log">The log.</param>
public DryRunScriptHost(ICakeEngine engine, ICakeContext context, ICakeLog log)
: base(engine, context, log)
{
}
}

/// <summary>
/// The script host used to dry run Cake scripts.
/// </summary>
/// <typeparam name="TContext">The context.</typeparam>
public class DryRunScriptHost<TContext> : ScriptHost
where TContext : ICakeContext
{
private readonly ICakeLog _log;

/// <summary>
/// Initializes a new instance of the <see cref="DryRunScriptHost{TContext}"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="context">The context.</param>
/// <param name="log">The log.</param>
public DryRunScriptHost(ICakeEngine engine, TContext context, ICakeLog log)
: base(engine, context)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Cake.Core.Graph;
using Cake.Core.Scripting;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
/// <summary>
/// The script host used for showing task descriptions.
Expand Down
Loading