Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Use System.CommandLine.Experimental instead of NDesk.Options #347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cdd46f7
Merge pull request #1 from Code52/master
biohazard999 Sep 4, 2019
af746d5
Merge branch 'master' of https://github.com/Code52/pretzel
biohazard999 Sep 5, 2019
6a99682
Merge branch 'master' of https://github.com/Code52/pretzel
biohazard999 Sep 13, 2019
4e9edfd
Merge branch 'master' of https://github.com/Code52/pretzel
biohazard999 Sep 16, 2019
0eb174e
Merge branch 'master' of https://github.com/biohazard999/pretzel
biohazard999 Sep 18, 2019
f4171c0
Merge branch 'master' of https://github.com/Code52/pretzel
biohazard999 Sep 18, 2019
0f35094
feat: replace NDesk.Options by System.CommandLine.Experimental
biohazard999 Sep 18, 2019
e8a5e68
feat: CommandParameters use new Option syntax
biohazard999 Sep 18, 2019
139b06f
feat: basic ground for new command system
biohazard999 Sep 21, 2019
1ed6152
refactor: BuiltInCommands
biohazard999 Sep 21, 2019
35545f0
feat: new CommandParameters almost working
biohazard999 Sep 21, 2019
8351e5f
refactor: removed old Parameter classes
biohazard999 Sep 21, 2019
4d93f5d
fixed: parameter prefixes
biohazard999 Sep 21, 2019
cb32029
feat: commands are back and running
biohazard999 Sep 22, 2019
00596b5
refactor: namespace cleanup
biohazard999 Sep 22, 2019
395fb17
test: removed noptions
biohazard999 Sep 22, 2019
9619f66
refactor: cleanup namespaces
biohazard999 Sep 23, 2019
5572e6d
test: BakeParameters
biohazard999 Sep 23, 2019
bb87e94
test: TasteCommandParameters
biohazard999 Sep 23, 2019
9700e03
refactor: tests use paramters hierarchy
biohazard999 Sep 23, 2019
28f3166
test: added IngredientCommandParametersTests
biohazard999 Sep 23, 2019
a99bd03
test: added RecipeCommandParametersTests
biohazard999 Sep 23, 2019
63b2cf0
test: added ImportCommandParametersTests
biohazard999 Sep 23, 2019
473071d
refactor: moved files to respective files
biohazard999 Sep 24, 2019
61545ae
Merge remote-tracking branch 'github/master' into topic/System.Comman…
biohazard999 Sep 24, 2019
3610fe7
fix: removed wrong PackageReferences
biohazard999 Sep 24, 2019
2169730
test: AzureHostSupport & VirtualDirectorySupport
biohazard999 Sep 24, 2019
5ec0c82
refactor: removed old parameter tests
biohazard999 Sep 24, 2019
a7536ab
test: ICommandParametersExtentionsTests
biohazard999 Sep 25, 2019
8ba9c37
test: BaseParametersTests
biohazard999 Sep 25, 2019
f8b1ab8
test: CommandCollection tests
biohazard999 Sep 25, 2019
7450241
refactor: moved base classes to Logic & rename ICommand to IPretzelCo…
biohazard999 Sep 25, 2019
1481584
test: PretzelCommandHandlerTests
biohazard999 Sep 25, 2019
d1027f2
test: added missing DetectFromDirectory tests
biohazard999 Sep 26, 2019
630e7a0
refactor: removed namespaces
biohazard999 Sep 26, 2019
c5cf606
refactor: namespace
biohazard999 Sep 26, 2019
cea6a0a
refactor: removed redundant pragma warning supression
biohazard999 Sep 26, 2019
1091496
refactor: fixed a bunch of warnings
biohazard999 Sep 26, 2019
9bd0c2f
refactor: renamed IPathProvider to ISourcePathProvider
biohazard999 Sep 28, 2019
02aed7a
Merge remote-tracking branch 'github/master' into topic/System.Comman…
biohazard999 Sep 28, 2019
c354558
test: added Program integration & Argument tests
biohazard999 Sep 28, 2019
83956a0
refactor: renamed files containing generic types
biohazard999 Sep 30, 2019
6b38e44
Merge branch 'topic/System.CommandLine.Experimental-346' of https://g…
biohazard999 Sep 30, 2019
f96c859
refactor: removed obsolete parameter
biohazard999 Sep 30, 2019
416377b
refactor: Arguments now need to return options
biohazard999 Sep 30, 2019
825e851
feat: allow commands to return result code
biohazard999 Sep 30, 2019
80fe287
refactor: arguments & command streamlined
biohazard999 Sep 30, 2019
dd1f584
feat: command arguments are now passed to commands
biohazard999 Sep 30, 2019
8d9846b
refactor: commands now specify their arguments
biohazard999 Sep 30, 2019
51fe940
refactor: CommandArgumentExtenders now need to provide own options
biohazard999 Sep 30, 2019
cd5905f
test: command argument extentsion tests
biohazard999 Sep 30, 2019
0e4e2c0
docs: added command
biohazard999 Sep 30, 2019
fbff531
feat: extensible argument types
biohazard999 Sep 30, 2019
94659bb
refactor: Program does not need to be exported
biohazard999 Oct 6, 2019
f4638b6
fix: its not needed to pass the global options to the root command
biohazard999 Oct 6, 2019
36b2a68
test: composition uses SatisfyImports
biohazard999 Oct 6, 2019
cc10116
fix: source and s arguments without additional dashes
biohazard999 Oct 6, 2019
c085ee7
test: composition uses SatisfyImports
biohazard999 Oct 6, 2019
c3b99aa
fix: RootCommand does not need to be exported
biohazard999 Oct 6, 2019
b3c12a8
fix: don't use a root command to init the app
biohazard999 Oct 6, 2019
607bbad
refactor: moved commands to logic and removed redundant interfaces
biohazard999 Oct 7, 2019
641f690
refactor: removed redundant naming
biohazard999 Oct 7, 2019
67a30a4
fix: removed unused built in commands class
biohazard999 Oct 8, 2019
1419e28
fix: use attributes instead of build in command constants
biohazard999 Oct 8, 2019
5455afc
feat: extend command arguments by command name
biohazard999 Oct 8, 2019
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
23 changes: 23 additions & 0 deletions src/Pretzel.Logic/Commands/BakeBaseCommandArguments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.CommandLine;
using System.IO.Abstractions;

namespace Pretzel.Logic.Commands
{
public abstract class BakeBaseCommandArguments : PretzelBaseCommandArguments
{
protected BakeBaseCommandArguments(IFileSystem fileSystem) : base(fileSystem) { }

protected override IEnumerable<Option> CreateOptions() => base.CreateOptions().Concat(new[]
{
new Option(new [] { "-c", "--cleantarget" }, "Delete the target directory (_site by default)")
{
Argument = new Argument<bool>()
},
});

public bool CleanTarget { get; set; }
}
}
83 changes: 83 additions & 0 deletions src/Pretzel.Logic/Commands/BakeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Diagnostics;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
using Pretzel.Logic.Extensibility;
using Pretzel.Logic.Extensions;
using Pretzel.Logic.Templating.Context;

namespace Pretzel.Logic.Commands
{
[Shared]
[Export]
[CommandArguments]
public sealed class BakeCommandArguments : BakeBaseCommandArguments
{
[ImportingConstructor]
public BakeCommandArguments(IFileSystem fileSystem) : base(fileSystem) { }
}

[Shared]
[CommandInfo(
Name = "bake",
Description = "transforming content into a website",
ArgumentsType = typeof(BakeCommandArguments),
CommandType = typeof(BakeCommand)
)]
public sealed class BakeCommand : Command<BakeCommandArguments>
{
[Import]
public TemplateEngineCollection TemplateEngines { get; set; }

[Import]
public SiteContextGenerator Generator { get; set; }

[ImportMany]
public IEnumerable<ITransform> Transforms { get; set; }

[Import]
public IFileSystem FileSystem { get; set; }

protected override Task<int> Execute(BakeCommandArguments arguments)
{
Tracing.Info("bake - transforming content into a website");

var siteContext = Generator.BuildContext(arguments.Source, arguments.Destination, arguments.Drafts);

if (arguments.CleanTarget && FileSystem.Directory.Exists(siteContext.OutputFolder))
{
FileSystem.Directory.Delete(siteContext.OutputFolder, true);
}

if (string.IsNullOrWhiteSpace(arguments.Template))
{
arguments.DetectFromDirectory(TemplateEngines.Engines, siteContext);
}

var engine = TemplateEngines[arguments.Template];
if (engine != null)
{
var watch = new Stopwatch();
watch.Start();
engine.Initialize();
engine.Process(siteContext);
foreach (var t in Transforms)
t.Transform(siteContext);

engine.CompressSitemap(siteContext, FileSystem);

watch.Stop();
Tracing.Info("done - took {0}ms", watch.ElapsedMilliseconds);
}
else
{
Tracing.Info("Cannot find engine for input: '{0}'", arguments.Template);
return Task.FromResult(1);
}
return Task.FromResult(0);
}
}
}
28 changes: 28 additions & 0 deletions src/Pretzel.Logic/Commands/BaseCommandArguments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Pretzel.Logic.Extensibility;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Composition;
using System.Linq;

namespace Pretzel.Logic.Commands
{
public abstract class BaseCommandArguments : ICommandArguments
{
readonly List<Option> options = new List<Option>();
[Export]
public IList<Option> Options => options;
public IList<ICommandArgumentsExtension> Extensions { get; } = new List<ICommandArgumentsExtension>();

internal void BuildOptions()
{
options.AddRange(CreateOptions());
}

protected abstract IEnumerable<Option> CreateOptions();

public virtual void BindingCompleted()
{
}
}
}
67 changes: 0 additions & 67 deletions src/Pretzel.Logic/Commands/BaseParameters.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/Pretzel.Logic/Commands/CommandArgumentsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Composition;

namespace Pretzel.Logic.Commands
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class CommandArgumentsAttribute : ExportAttribute
{
public CommandArgumentsAttribute() : base(typeof(ICommandArguments))
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using System;
using System.Composition;

namespace Pretzel.Commands
namespace Pretzel.Logic.Commands
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class CommandInfoAttribute : ExportAttribute
{
public string CommandName { get; set; }
public string Name { get; set; }

public string Description { get; set; }

public Type ArgumentsType { get; set; }

public Type CommandType { get; set; }

public CommandInfoAttribute() : base(typeof(ICommand))
{
Expand Down
Loading