Skip to content

Commit

Permalink
Add .NET API (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Jul 28, 2023
1 parent e773b63 commit c2b259c
Show file tree
Hide file tree
Showing 184 changed files with 4,560 additions and 2,326 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ dotnet_diagnostic.IDE0079.severity = none
dotnet_diagnostic.IDE0090.severity = none
dotnet_diagnostic.IDE0220.severity = none
dotnet_diagnostic.IDE1005.severity = suggestion
dotnet_diagnostic.IDE0220.severity = none
dotnet_diagnostic.IDE1006.severity = suggestion

dotnet_diagnostic.RS1024.severity = none # Compare symbols correctly
Expand Down
45 changes: 25 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,56 @@ on:

jobs:

build_packages:
build:
runs-on: ubuntu-20.04
env:
Configuration: Release
TreatWarningsAsErrors: true
WarningsNotAsErrors: 1591
Deterministic: true
defaults:
run:
working-directory: src
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update path
run: echo ":/github/home/.dotnet/tools" >> $GITHUB_PATH
- run: dotnet tool install -g GitVersion.Tool --version 5.10.1 --ignore-failed-sources
- run: dotnet tool install -g dotnet-validate --version 0.0.1-preview.304
- name: Resolve semantic version
id: semantic_version
- run: dotnet tool install -g GitVersion.Tool --version 5.10.0
- name: Resolve version
id: version
run: |
semantic_version=$(dotnet-gitversion /showvariable SemVer)
echo "semantic_version=$semantic_version" >> $GITHUB_ENV
working-directory: ./
dotnet-gitversion > version.json
version="$(jq -r '.SemVer' version.json)"
pr_version="$(jq -r '.MajorMinorPatch' version.json)-$(jq -r '.PreReleaseLabel' version.json).${{ github.run_number }}.${{ github.run_attempt }}"
if [ "${{ github.event_name }}" = "pull_request" ]; then version=$pr_version; fi
echo "Resolved version: $version"
echo "Version=${version}" >> "$GITHUB_ENV"
- run: dotnet restore --configfile nuget.config
- run: dotnet format --no-restore --verify-no-changes --severity info --exclude-diagnostics IDE0270
- run: dotnet build --no-restore /p:Version=${{ env.semantic_version }}
- run: dotnet build --no-restore
- run: dotnet test --no-build
- run: dotnet pack --no-build /p:PackageVersion=${{ env.semantic_version }}
- run: dotnet pack --no-build
- uses: actions/upload-artifact@v3
with:
name: nuget_packages
path: src/CommandLine/bin/Release/*nupkg
path: src/CommandLine/bin/Release/*.*nupkg
- uses: actions/upload-artifact@v3
with:
name: nuget_packages
path: src/Common/bin/Release/*nupkg
- uses: actions/upload-artifact@v3
with:
name: nuget_packages
path: src/FileSystem/bin/Release/*.*nupkg

release_packages:
publish:
runs-on: ubuntu-20.04
needs: [build_packages]
needs: [build]
if: github.ref_type == 'tag'
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
steps:
- uses: actions/download-artifact@v3
with:
name: nuget_packages
path: nuget_packages
- run: dotnet nuget push "*.nupkg" -k NUGET_API_KEY -s "https://api.nuget.org/v3/index.json"
- run: dotnet nuget push "*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s "https://api.nuget.org/v3/index.json" --skip-duplicate
working-directory: nuget_packages
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add [.NET API](https://josefpihrt.github.io/docs/orang/ref) ([#51](https://github.com/josefpihrt/roslynator/pull/51)).

### Changed

- Migrate documentation to [Docusaurus](https://josefpihrt.github.io/docs/orang) ([#48](https://github.com/josefpihrt/roslynator/pull/48)).
Expand Down
11 changes: 10 additions & 1 deletion src/CommandLine.Core/CommandLine.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Orang, PublicKey=$(OrangPublicKey)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Orang.DocumentationGenerator, PublicKey=$(OrangPublicKey)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/CommandLine.Core/Help/CommandHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public CommandHelp(
public static CommandHelp Create(
Command command,
IEnumerable<OptionValueProvider>? providers = null,
Filter? filter = null)
Matcher? matcher = null)
{
ImmutableArray<ArgumentItem> arguments = (command.Arguments.Any())
? HelpProvider.GetArgumentItems(command.Arguments, filter)
? HelpProvider.GetArgumentItems(command.Arguments, matcher)
: ImmutableArray<ArgumentItem>.Empty;

ImmutableArray<OptionItem> options = HelpProvider.GetOptionItems(command.Options, filter);
ImmutableArray<OptionItem> options = HelpProvider.GetOptionItems(command.Options, matcher);

ImmutableArray<OptionValueItemList> values = HelpProvider.GetOptionValues(
command.Options,
providers ?? ImmutableArray<OptionValueProvider>.Empty,
filter);
matcher);

return new CommandHelp(command, arguments, options, values);
}
Expand Down
6 changes: 3 additions & 3 deletions src/CommandLine.Core/Help/CommandsHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public CommandsHelp(
public static CommandsHelp Create(
IEnumerable<Command> commands,
IEnumerable<OptionValueProvider>? providers = null,
Filter? filter = null)
Matcher? matcher = null)
{
ImmutableArray<CommandItem> commandsHelp = HelpProvider.GetCommandItems(commands, filter);
ImmutableArray<CommandItem> commandsHelp = HelpProvider.GetCommandItems(commands, matcher);

ImmutableArray<OptionValueItemList> values = HelpProvider.GetOptionValues(
commands.SelectMany(f => f.Options),
providers ?? ImmutableArray<OptionValueProvider>.Empty,
filter);
matcher);

return new CommandsHelp(commandsHelp, values);
}
Expand Down
38 changes: 19 additions & 19 deletions src/CommandLine.Core/Help/HelpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class HelpProvider
{
public const int SeparatorWidth = 2;

public static ImmutableArray<CommandItem> GetCommandItems(IEnumerable<Command> commands, Filter? filter = null)
public static ImmutableArray<CommandItem> GetCommandItems(IEnumerable<Command> commands, Matcher? matcher = null)
{
if (!commands.Any())
return ImmutableArray<CommandItem>.Empty;
Expand All @@ -33,7 +33,7 @@ public static ImmutableArray<CommandItem> GetCommandItems(IEnumerable<Command> c

var commandItem = new CommandItem(command, syntax, description);

if (filter?.IsMatch(commandItem.Text) != false)
if (matcher?.IsMatch(commandItem.Text) != false)
builder.Add(commandItem);
}

Expand All @@ -42,7 +42,7 @@ public static ImmutableArray<CommandItem> GetCommandItems(IEnumerable<Command> c

public static ImmutableArray<ArgumentItem> GetArgumentItems(
IEnumerable<CommandArgument> arguments,
Filter? filter = null)
Matcher? matcher = null)
{
int width = CalculateArgumentsWidths(arguments);

Expand All @@ -66,7 +66,7 @@ public static ImmutableArray<ArgumentItem> GetArgumentItems(

var argumentItem = new ArgumentItem(argument, syntax, description);

if (filter?.IsMatch(argumentItem.Text) != false)
if (matcher?.IsMatch(argumentItem.Text) != false)
{
builder.Add(argumentItem);
}
Expand All @@ -75,7 +75,7 @@ public static ImmutableArray<ArgumentItem> GetArgumentItems(
return builder.ToImmutableArray();
}

public static ImmutableArray<OptionItem> GetOptionItems(IEnumerable<CommandOption> options, Filter? filter = null)
public static ImmutableArray<OptionItem> GetOptionItems(IEnumerable<CommandOption> options, Matcher? matcher = null)
{
int width = CalculateOptionsWidths(options);

Expand Down Expand Up @@ -119,7 +119,7 @@ public static ImmutableArray<OptionItem> GetOptionItems(IEnumerable<CommandOptio

var optionItem = new OptionItem(option, syntax: syntax, description);

if (filter?.IsMatch(optionItem.Text) != false)
if (matcher?.IsMatch(optionItem.Text) != false)
builder.Add(optionItem);
}

Expand All @@ -129,7 +129,7 @@ public static ImmutableArray<OptionItem> GetOptionItems(IEnumerable<CommandOptio
public static ImmutableArray<OptionValueItemList> GetOptionValues(
IEnumerable<CommandOption> options,
IEnumerable<OptionValueProvider> providers,
Filter? filter = null)
Matcher? matcher = null)
{
providers = OptionValueProvider.GetProviders(options, providers).ToImmutableArray();

Expand All @@ -147,8 +147,8 @@ public static ImmutableArray<OptionValueItemList> GetOptionValues(
builder.Add(new OptionValueItemList(provider.Name, valueItems));
}

return (filter is not null)
? FilterOptionValues(builder, filter)
return (matcher is not null)
? FilterOptionValues(builder, matcher)
: builder.ToImmutableArray();
}

Expand Down Expand Up @@ -192,20 +192,20 @@ public static ImmutableArray<OptionValueItem> GetOptionValueItems(

private static ImmutableArray<OptionValueItemList> FilterOptionValues(
IEnumerable<OptionValueItemList> values,
Filter filter)
Matcher matcher)
{
ImmutableArray<OptionValueItemList>.Builder builder = ImmutableArray.CreateBuilder<OptionValueItemList>();

foreach (OptionValueItemList valueList in values)
{
if (filter.IsMatch(valueList.MetaValue))
if (matcher.IsMatch(valueList.MetaValue))
{
builder.Add(valueList);
}
else
{
ImmutableArray<OptionValueItem> valueItems = valueList.Values
.Where(f => filter.IsMatch(f.Text))
.Where(f => matcher.IsMatch(f.Text))
.ToImmutableArray();

if (valueItems.Any())
Expand Down Expand Up @@ -261,15 +261,15 @@ public static ImmutableArray<string> GetExpressionLines(string? variableName = n
variableName ??= "x";

builder.Add(($"{variableName}=n", ""));
builder.Add(($"{variableName}<n", ""));
builder.Add(($"{variableName}>n", ""));
builder.Add(($"{variableName}<=n", ""));
builder.Add(($"{variableName}>=n", ""));
builder.Add(($"{variableName}=<min;max>", "Inclusive interval"));
builder.Add(($"{variableName}=(min;max)", "Exclusive interval"));
builder.Add(($@"""{variableName}<n""", ""));
builder.Add(($@"""{variableName}>n""", ""));
builder.Add(($@"""{variableName}<=n""", ""));
builder.Add(($@" ""{variableName}>=n""", ""));
builder.Add(($@" ""{variableName}=<min;max>""", "Inclusive interval"));
builder.Add(($@" ""{variableName}=(min;max)""", "Exclusive interval"));

if (includeDate)
builder.Add(($"{variableName}=-d|[d.]hh:mm[:ss]", $"{variableName} is greater than actual date - <VALUE>"));
builder.Add(($@"""{variableName}=-d|[d.]hh:mm[:ss]""", $"{variableName} is greater than actual date - <VALUE>"));

return builder.ToImmutableArray();
}
Expand Down
23 changes: 20 additions & 3 deletions src/CommandLine.Core/Help/HelpWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public virtual void WriteCommand(CommandHelp commandHelp)
WriteArguments(arguments);
WriteEndArguments(commandHelp);
}
else if (Options.Filter is not null
else if (Options.Matcher is not null
&& commandHelp.Command.Arguments.Any())
{
WriteLine();
Expand All @@ -42,7 +42,7 @@ public virtual void WriteCommand(CommandHelp commandHelp)
WriteOptions(options);
WriteEndOptions(commandHelp);
}
else if (Options.Filter is not null
else if (Options.Matcher is not null
&& commandHelp.Command.Options.Any())
{
WriteLine();
Expand Down Expand Up @@ -114,7 +114,7 @@ public virtual void WriteCommands(CommandsHelp commandsHelp)

WriteEndCommands(commandsHelp);
}
else if (Options.Filter is not null)
else if (Options.Matcher is not null)
{
WriteLine("No command found");
}
Expand Down Expand Up @@ -171,6 +171,23 @@ public void WriteValues(IEnumerable<OptionValueItemList> optionValues)
}
}

public void WriteExpressionSyntax(IEnumerable<OptionValueItemList> optionValues)
{
ImmutableArray<string> expressions = HelpProvider.GetExpressionItems(optionValues);

if (!expressions.IsEmpty)
{
WriteLine();
WriteHeading("Expression syntax");

foreach (string expression in expressions)
{
Write(Options.Indent);
WriteLine(expression);
}
}
}

private void WriteValues(ImmutableArray<OptionValueItem> values)
{
foreach (OptionValueItem value in values)
Expand Down
6 changes: 3 additions & 3 deletions src/CommandLine.Core/Help/HelpWriterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public class HelpWriterOptions

public HelpWriterOptions(
string indent = " ",
Filter? filter = null)
Matcher? matcher = null)
{
Indent = indent;
Filter = filter;
Matcher = matcher;
}

public string Indent { get; }

public Filter? Filter { get; }
public Matcher? Matcher { get; }
}
8 changes: 0 additions & 8 deletions src/CommandLine.Core/Properties/AssemblyInfo.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/CommandLine/Aggregation/StorageSectionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ private class PathStorageSectionComparer : StorageSectionComparer
{
public override int Compare([AllowNull] StorageSection x, [AllowNull] StorageSection y)
{
return FileSystemHelpers.Comparer.Compare(x.FileMatch?.Path, y.FileMatch?.Path);
return FileSystemUtilities.Comparer.Compare(x.FileMatch?.Path, y.FileMatch?.Path);
}

public override bool Equals([AllowNull] StorageSection x, [AllowNull] StorageSection y)
{
return FileSystemHelpers.Comparer.Equals(x.FileMatch?.Path, y.FileMatch?.Path);
return FileSystemUtilities.Comparer.Equals(x.FileMatch?.Path, y.FileMatch?.Path);
}

public override int GetHashCode([DisallowNull] StorageSection obj)
Expand All @@ -35,7 +35,7 @@ public override int GetHashCode([DisallowNull] StorageSection obj)
if (path is null)
return 0;

return FileSystemHelpers.Comparer.GetHashCode(path);
return FileSystemUtilities.Comparer.GetHashCode(path);
}
}
}
Loading

0 comments on commit c2b259c

Please sign in to comment.