Skip to content

Commit

Permalink
Fix interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
olsh committed Oct 15, 2022
1 parent c526bc3 commit 4b61d1f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ dotnet add package Curl.HttpClient.Converter
#### Usage/Examples
```c#
var input = @"curl https://sentry.io/api/0/projects/1/groups/?status=unresolved -d '{""status"": ""resolved""}' -H 'Content-Type: application/json' -u 'username:password' -H 'Accept: application/json' -H 'User-Agent: curl/7.60.0'";
var curlOption = new CurlParser(new ParsingOptions() { MaxUploadFiles = 10 }).Parse(input);
var output = new CurlConverter().ToCsharp(curlOption.Data);
var curlOption = new CurlParser().Parse(input);
var output = new CurlHttpClientConverter().ToCsharp(curlOption.Data);
// Output:
/*
// In production code, don't destroy the HttpClient through using, but better reuse an existing instance
Expand Down
4 changes: 4 additions & 0 deletions src/Curl.CommandLine.Parser/CurlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class CurlParser : ICurlParser
{
private readonly IEnumerable<ParameterEvaluator> _evaluators;

public CurlParser() : this(new ParsingOptions(10))
{
}

public CurlParser(ParsingOptions parsingOptions)
: this(EvaluatorProvider.All(parsingOptions))
{
Expand Down
2 changes: 2 additions & 0 deletions src/Curl.CommandLine.Parser/ICurlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ namespace Curl.CommandLine.Parser
public interface ICurlParser
{
ConvertResult<CurlOptions> Parse(Span<char> commandLine);

ConvertResult<CurlOptions> Parse(string commandLine);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Curl.HttpClient.Converter
{
public class CurlConverter : ICurlConverter
public class CurlHttpClientConverter : ICurlConverter
{
private const string RequestVariableName = "request";

Expand Down Expand Up @@ -472,7 +472,7 @@ private StatementSyntax[] CreateBasicAuthorizationStatements(CurlOptions options
return new StatementSyntax[] { authorizationEncodingStatement, tryAddHeaderStatement };
}

public ExpressionStatementSyntax CreateSetHttpVersionStatement(CurlOptions options)
private ExpressionStatementSyntax CreateSetHttpVersionStatement(CurlOptions options)
{
var arguments = new LinkedList<ArgumentSyntax>();
var majorVersionArgument = options.HttpVersion switch
Expand Down
2 changes: 1 addition & 1 deletion src/CurlToCSharp.IntegrationTests/RequestsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static Task<string> ExecuteCurlRequestAsync(string curlArguments)
private static async Task<string> ExecuteCsharpRequestAsync(string curlArguments)
{
var commandLineParser = new CurlParser(new ParsingOptions(int.MaxValue));
var converterService = new CurlConverter();
var converterService = new CurlHttpClientConverter();
var parserResult = commandLineParser.Parse(new Span<char>($"curl {curlArguments}".ToCharArray()));
var csharp = converterService.ToCsharp(parserResult.Data);

Expand Down
4 changes: 2 additions & 2 deletions src/CurlToCSharp.UnitTests/Services/ConverterServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ConverterServiceTests
[Fact]
public void ToCsharp_ValidCurlOptions_CanBeCompiled()
{
var converterService = new CurlConverter();
var converterService = new CurlHttpClientConverter();
var curlOptions = new CurlOptions
{
HttpMethod = HttpMethod.Post.ToString().ToUpper(),
Expand All @@ -37,7 +37,7 @@ public void ToCsharp_ValidCurlOptions_CanBeCompiled()
[Fact]
public void ToCsharp_GetRequest_ContainsSendStatement()
{
var converterService = new CurlConverter();
var converterService = new CurlHttpClientConverter();
var curlOptions = new CurlOptions
{
HttpMethod = HttpMethod.Get.ToString().ToUpper(),
Expand Down
2 changes: 1 addition & 1 deletion src/CurlToCSharp/Infrastructure/IocExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public static void RegisterServices(this IServiceCollection services)
.Value.Parsing);

services.AddSingleton<ICurlParser, CurlParser>();
services.AddSingleton<ICurlConverter, CurlConverter>();
services.AddSingleton<ICurlConverter, CurlHttpClientConverter>();
}
}
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build">
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionPrefix>1.0.1</VersionPrefix>
</PropertyGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('Tests'))">
Expand Down

0 comments on commit 4b61d1f

Please sign in to comment.