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 60 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Pretzel.Logic/Commands/BakeBaseCommandArguments.cs
@@ -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, IBakeBaseCommandArguments
{
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; }
}
}
28 changes: 28 additions & 0 deletions src/Pretzel.Logic/Commands/BaseCommandArguments.cs
@@ -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.

13 changes: 13 additions & 0 deletions src/Pretzel.Logic/Commands/BuiltInCommands.cs
@@ -0,0 +1,13 @@
namespace Pretzel.Logic.Commands
{
public static class BuiltInCommands
{
public const string Bake = "bake";
laedit marked this conversation as resolved.
Show resolved Hide resolved
public const string Hungry = "hungry";
public const string Import = "import";
public const string Ingredient = "ingredient";
public const string Create = "create";
public const string Taste = "taste";
public const string Version = "version";
}
}
14 changes: 14 additions & 0 deletions src/Pretzel.Logic/Commands/CommandArgumentsAttribute.cs
@@ -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))
{
}
}
}
@@ -1,14 +1,18 @@
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; }
laedit marked this conversation as resolved.
Show resolved Hide resolved

public string CommandDescription { get; set; }

public Type CommandArgumentsType { get; set; }

public CommandInfoAttribute() : base(typeof(ICommand))
{
}
Expand Down
158 changes: 0 additions & 158 deletions src/Pretzel.Logic/Commands/CommandParameters.cs

This file was deleted.

11 changes: 11 additions & 0 deletions src/Pretzel.Logic/Commands/IBakeBaseCommandArguments.cs
@@ -0,0 +1,11 @@
using System;
using System.Linq;

namespace Pretzel.Logic.Commands
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public interface IBakeBaseCommandArguments : IPretzelBaseCommandArguments
{
bool CleanTarget { get; }
}
}
10 changes: 10 additions & 0 deletions src/Pretzel.Logic/Commands/IBakeCommandArguments.cs
@@ -0,0 +1,10 @@
using System;
using System.Linq;

namespace Pretzel.Logic.Commands
{
public interface IBakeCommandArguments : IBakeBaseCommandArguments
{

}
}
30 changes: 30 additions & 0 deletions src/Pretzel.Logic/Commands/ICommand.cs
@@ -0,0 +1,30 @@
using System.Threading.Tasks;

namespace Pretzel.Logic.Commands
{
/// <summary>
/// Defines a custom command for pretzel. Implementors should be decorated with the <see cref="CommandInfoAttribute"/>
/// Also see <see cref="Command{T}"/> for easier implementation.
/// </summary>
public interface ICommand
{
/// <summary>
/// Executes the specified command with arguments provided defined in <see cref="CommandInfoAttribute.CommandArgumentsType"/>.
/// </summary>
/// <param name="arguments">The arguments.</param>
/// <returns></returns>
Task<int> Execute(ICommandArguments arguments);
}

/// <summary>
/// Defines a custom command for pretzel. Implementors should be decorated with the <see cref="CommandInfoAttribute"/>
/// </summary>
public abstract class Command<T> : ICommand where T : ICommandArguments
{
public Task<int> Execute(ICommandArguments arguments)
=> Execute((T)arguments);

protected abstract Task<int> Execute(T arguments);
}

}