Skip to content

Commit

Permalink
More control over command default features
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Nov 24, 2019
1 parent f2f0603 commit 1d67972
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 27 deletions.
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 1.0.0-alpha.20

- Split `DefaultFeatures.Commands` into `DefaultFeatures.BuildCommands`, `DefaultFeatures.HostingCommands`, and `DefaultFeatures.CustomCommands` for finer control.
- Renamed `DefaultsToAdd` to `DefaultFeatures`.
- Adds a new `ThrowException` module that can be used to throw exceptions based on a config value.
- Renames `BuildCommand` to `PipelinesCommand`.
- Refactors default commands by renaming `build` to `pipelines` and accepting pipelines to execute as an argument (moving the root path to an option).
Expand Down
12 changes: 6 additions & 6 deletions src/core/Statiq.App/Bootstrapper/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<int> RunAsync()
/// </summary>
/// <remarks>
/// Use this method when you want to fully customize the bootstrapper and engine.
/// Otherwise use on of the <see cref="CreateDefault(string[], DefaultsToAdd)"/> overloads to
/// Otherwise use on of the <see cref="CreateDefault(string[], DefaultFeatures)"/> overloads to
/// create an initialize a bootstrapper with an initial set of default configurations.
/// </remarks>
/// <param name="args">The command line arguments.</param>
Expand All @@ -131,12 +131,12 @@ public async Task<int> RunAsync()
/// shortcodes, and assembly scanning.
/// </summary>
/// <param name="args">The command line arguments.</param>
/// <param name="defaultsToAdd">The default configurations to add to the bootstrapper.</param>
/// <param name="features">The default configurations to add to the bootstrapper.</param>
/// <returns>The bootstrapper.</returns>
public static IBootstrapper CreateDefault(string[] args, DefaultsToAdd defaultsToAdd = DefaultsToAdd.All) =>
Create(args).AddDefaults(defaultsToAdd);
public static IBootstrapper CreateDefault(string[] args, DefaultFeatures features = DefaultFeatures.All) =>
Create(args).AddDefaults(features);

public static IBootstrapper CreateDefaultWithout(string[] args, DefaultsToAdd withoutDefaults) =>
Create(args).AddDefaultsWithout(withoutDefaults);
public static IBootstrapper CreateDefaultWithout(string[] args, DefaultFeatures features) =>
Create(args).AddDefaultsWithout(features);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
namespace Statiq.App
{
[Flags]
public enum DefaultsToAdd
public enum DefaultFeatures
{
None = 0,
BootstrapperConfigurators = 1 << 0,
Logging = 1 << 1,
Settings = 1 << 2,
EnvironmentVariables = 1 << 3,
ConfigurationFiles = 1 << 4,
Commands = 1 << 5,
Shortcodes = 1 << 6,
Namespaces = 1 << 7,
Pipelines = 1 << 8,
BuildCommands = 1 << 5,
HostingCommands = 1 << 6,
CustomCommands = 1 << 7,
Shortcodes = 1 << 8,
Namespaces = 1 << 9,
Pipelines = 1 << 10,
All =
BootstrapperConfigurators
| Logging
| Settings
| EnvironmentVariables
| ConfigurationFiles
| Commands
| BuildCommands
| HostingCommands
| CustomCommands
| Shortcodes
| Namespaces
| Pipelines
Expand Down
49 changes: 34 additions & 15 deletions src/core/Statiq.App/Bootstrapper/IBootstrapper.DefaultDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,57 @@ namespace Statiq.App
{
public partial interface IBootstrapper
{
public IBootstrapper AddDefaults(DefaultsToAdd defaultsToAdd = DefaultsToAdd.All)
public IBootstrapper AddDefaults(DefaultFeatures features = DefaultFeatures.All)
{
if (defaultsToAdd.HasFlag(DefaultsToAdd.BootstrapperConfigurators))
if (features.HasFlag(DefaultFeatures.BootstrapperConfigurators))
{
AddBootstrapperConfigurators();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.Logging))
if (features.HasFlag(DefaultFeatures.Logging))
{
AddDefaultLogging();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.Settings))
if (features.HasFlag(DefaultFeatures.Settings))
{
AddDefaultSettings();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.EnvironmentVariables))
if (features.HasFlag(DefaultFeatures.EnvironmentVariables))
{
AddEnvironmentVariables();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.ConfigurationFiles))
if (features.HasFlag(DefaultFeatures.ConfigurationFiles))
{
AddDefaultConfigurationFiles();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.Commands))
if (features.HasFlag(DefaultFeatures.BuildCommands))
{
AddDefaultCommands();
AddBuildCommands();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.Shortcodes))
if (features.HasFlag(DefaultFeatures.HostingCommands))
{
AddHostingCommands();
}
if (features.HasFlag(DefaultFeatures.CustomCommands))
{
AddCustomCommands();
}
if (features.HasFlag(DefaultFeatures.Shortcodes))
{
AddDefaultShortcodes();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.Namespaces))
if (features.HasFlag(DefaultFeatures.Namespaces))
{
AddDefaultNamespaces();
}
if (defaultsToAdd.HasFlag(DefaultsToAdd.Pipelines))
if (features.HasFlag(DefaultFeatures.Pipelines))
{
AddDefaultPipelines();
}
return this;
}

public IBootstrapper AddDefaultsWithout(DefaultsToAdd withoutDefaults) =>
AddDefaults(DefaultsToAdd.All & ~withoutDefaults);
public IBootstrapper AddDefaultsWithout(DefaultFeatures withoutFeatures) =>
AddDefaults(DefaultFeatures.All & ~withoutFeatures);

public IBootstrapper AddBootstrapperConfigurators()
{
Expand Down Expand Up @@ -100,13 +108,24 @@ public IBootstrapper AddDefaultConfigurationFiles() =>
.AddJsonFile("appsettings.json", true)
.AddJsonFile("statiq.json", true));

public IBootstrapper AddDefaultCommands()
public IBootstrapper AddBuildCommands()
{
SetDefaultCommand<PipelinesCommand<PipelinesCommandSettings>>();
AddCommand<PipelinesCommand<PipelinesCommandSettings>>();
AddCommand<PreviewCommand>();
AddCommand<DeployCommand>();
AddCommands();
return this;
}

public IBootstrapper AddHostingCommands()
{
AddCommand<PreviewCommand>();
AddCommand<ServeCommand>();
return this;
}

public IBootstrapper AddCustomCommands()
{
AddCommands();
return this;
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/Statiq.Hosting/Statiq.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\Statiq.Common\Statiq.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\" />
</ItemGroup>
</Project>

0 comments on commit 1d67972

Please sign in to comment.