Skip to content

Commit 7af6655

Browse files
committed
Update dependencies
1 parent d1877fb commit 7af6655

File tree

8 files changed

+39
-44
lines changed

8 files changed

+39
-44
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup .NET Core
1616
uses: actions/setup-dotnet@v1
1717
with:
18-
dotnet-version: 3.1.301
18+
dotnet-version: 6.0.100
1919
- name: Install dependencies
2020
run: dotnet restore
2121
- name: Build

dotnet-json.Tests/FileArgumentTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ public async Task DoesNotThrowOnNonExistingFileIfAllowNewFileIsTrue()
7373

7474
var console = new TestConsole();
7575

76-
command.Handler = CommandHandler.Create((string file) =>
76+
command.SetHandler((string file) =>
7777
{
7878
console.Out.Write("Success " + file);
79-
return 0;
80-
});
79+
}, file);
8180

8281
var exitCode = await command.InvokeAsync(filename, console);
8382
return (exitCode, console);

dotnet-json.Tests/JsonDocumentTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public void SetValue_ModifiesOriginalDocument_Object()
112112

113113
document._json.Should().BeOfType<JObject>()
114114
.Which.Should().ContainKey("nested")
115-
.WhichValue.Should().BeOfType<JObject>()
115+
.WhoseValue.Should().BeOfType<JObject>()
116116
.Which.Should().ContainKey("another")
117-
.WhichValue.Should().BeOfType<JValue>()
117+
.WhoseValue.Should().BeOfType<JValue>()
118118
.Which.Value.Should().Be("something else");
119119
}
120120

@@ -127,9 +127,9 @@ public void SetValue_ModifiesOriginalDocument_Array()
127127

128128
document._json.Should().BeOfType<JObject>()
129129
.Which.Should().ContainKey("nested")
130-
.WhichValue.Should().BeOfType<JObject>()
130+
.WhoseValue.Should().BeOfType<JObject>()
131131
.Which.Should().ContainKey("another")
132-
.WhichValue.Should().BeOfType<JValue>()
132+
.WhoseValue.Should().BeOfType<JValue>()
133133
.Which.Value.Should().Be("something else");
134134
}
135135

@@ -235,7 +235,7 @@ public void SetValue_CreatesNestedStructure_Multi()
235235
.Which.Should().ContainSingle()
236236
.Which.Should().BeOfType<JObject>()
237237
.Which.Should().ContainKey("nested")
238-
.WhichValue.Should().BeOfType<JValue>()
238+
.WhoseValue.Should().BeOfType<JValue>()
239239
.Which.Value.Should().Be("value");
240240
}
241241

@@ -248,7 +248,7 @@ public void Remove_ModifiesOriginalDocument_Property()
248248

249249
document._json.Should().BeOfType<JObject>()
250250
.Which.Should().ContainKey("nested")
251-
.WhichValue.Should().BeOfType<JObject>()
251+
.WhoseValue.Should().BeOfType<JObject>()
252252
.Which.Should().NotContainKey("another")
253253
.And.ContainKey("extra");
254254
}
@@ -262,7 +262,7 @@ public void Remove_ModifiesOriginalDocument_Array()
262262

263263
document._json.Should().BeOfType<JObject>()
264264
.Which.Should().ContainKey("nested")
265-
.WhichValue.Should().BeOfType<JArray>()
265+
.WhoseValue.Should().BeOfType<JArray>()
266266
.Which.Should().BeEmpty();
267267
}
268268

dotnet-json.Tests/dotnet-json.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
<RootNamespace>dotnet_json.Tests</RootNamespace>
66
<IsPackable>false</IsPackable>
77
<IsPublishable>false</IsPublishable>
8-
8+
99
<LangVersion>8.0</LangVersion>
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="FluentAssertions" Version="6.0.0-alpha0002" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
14+
<PackageReference Include="FluentAssertions" Version="6.4.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1616
<PackageReference Include="xunit" Version="2.4.1" />
1717
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
18-
<PackageReference Include="coverlet.collector" Version="3.0.2" PrivateAssets="All" />
18+
<PackageReference Include="coverlet.collector" Version="3.1.1" PrivateAssets="All" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

dotnet-json/Commands/CommandBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Task<int> InvokeAsync(InvocationContext context)
4040

4141
protected Stream GetInputStream()
4242
{
43-
var filename = Context?.ParseResult.ValueForArgument(InputFile) ?? throw new Exception("GetInputStream must be called from a command handler");
43+
var filename = Context?.ParseResult.GetValueForArgument(InputFile) ?? throw new Exception("GetInputStream must be called from a command handler");
4444

4545
return filename switch
4646
{
@@ -52,8 +52,8 @@ protected Stream GetInputStream()
5252
protected Stream GetOutputStream()
5353
{
5454
var filename = Context?.ParseResult.HasOption(OutputFile) ?? throw new Exception("GetOutputStream() must be called from a command handler")
55-
? Context.ParseResult.ValueForOption(OutputFile)
56-
: Context.ParseResult.ValueForArgument(InputFile);
55+
? Context.ParseResult.GetValueForOption(OutputFile)
56+
: Context.ParseResult.GetValueForArgument(InputFile);
5757

5858
return filename switch
5959
{
@@ -73,13 +73,13 @@ protected Formatting GetFormatting()
7373
protected T GetParameterValue<T>(Argument<T> argument)
7474
{
7575
return (Context ?? throw new Exception("GetParameterValue() must be called from a command handler"))
76-
.ParseResult.ValueForArgument(argument);
76+
.ParseResult.GetValueForArgument(argument);
7777
}
7878

7979
protected List<T>? GetMultiParameterValue<T>(Argument<T> argument)
8080
{
8181
return (Context ?? throw new Exception("GetMultiParameterValue() must be called from a command handler"))
82-
.ParseResult.ValueForArgument<List<T>>(argument);
82+
.ParseResult.GetValueForArgument<List<T>>(argument);
8383
}
8484

8585
protected abstract Task<int> ExecuteAsync();

dotnet-json/Commands/FileOption.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
1-
using System;
21
using System.CommandLine;
2+
using System.IO;
3+
using System.Linq;
34

45
namespace dotnet_json.Commands
56
{
67
public class FileOption : Option<string>
78
{
8-
private bool _initialized = false;
9-
109
public FileOption(string alias, string? description = null)
1110
: base(alias, description)
1211
{
13-
base.Argument = new FileArgument("file") { Arity = ArgumentArity.ExactlyOne };
14-
_initialized = true;
12+
base.Arity = ArgumentArity.ExactlyOne;
13+
this.AddValidator();
1514
}
1615

1716
public FileOption(string[] aliases, string? description = null)
1817
: base(aliases, description)
1918
{
20-
base.Argument = new FileArgument("file") { Arity = ArgumentArity.ExactlyOne };
21-
_initialized = true;
19+
base.Arity = ArgumentArity.ExactlyOne;
20+
this.AddValidator();
2221
}
2322

24-
public bool AllowNewFile
25-
{
26-
get => ((FileArgument)Argument).AllowNewFile;
27-
set => ((FileArgument)Argument).AllowNewFile = value;
28-
}
23+
public bool AllowNewFile { get; set; }
2924

30-
public override Argument Argument
25+
private void AddValidator()
3126
{
32-
set
33-
{
34-
if (_initialized && !(value is FileArgument))
35-
throw new ArgumentException($"{nameof(Argument)} must be of type {typeof(FileArgument)} but was {value?.GetType().ToString() ?? "null"}");
36-
37-
base.Argument = value;
38-
}
27+
this.AddValidator(symbol =>
28+
symbol.Tokens
29+
.Select(t => t.Value)
30+
.Where(_ => !AllowNewFile) // Need to check AllowNewFile at this point because AddValidator() is called from constructor
31+
.Where(filePath => filePath != "-")
32+
.Where(filePath => !File.Exists(filePath))
33+
.Select(filePath => $"File does not exist: {filePath}")
34+
.FirstOrDefault());
3935
}
4036
}
4137
}

dotnet-json/Commands/GetCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected override async Task<int> ExecuteAsync()
3636
return 1;
3737
}
3838

39-
if (Context!.ParseResult.ValueForOption(Exact) && !(result is JValue))
39+
if (Context!.ParseResult.GetValueForOption(Exact) && !(result is JValue))
4040
{
4141
Context!.Console.Error.WriteLine($"Value for key '{key}' is a complex object.");
4242
return 1;

dotnet-json/dotnet-json.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RootNamespace>dotnet_json</RootNamespace>
77
<RollForward>LatestMajor</RollForward>
88

9-
<LangVersion>8.0</LangVersion>
9+
<LangVersion>9</LangVersion>
1010
<Nullable>enable</Nullable>
1111
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1212

@@ -28,8 +28,8 @@
2828
</PropertyGroup>
2929

3030
<ItemGroup>
31-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
32-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
31+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
32+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
3333
</ItemGroup>
3434

3535
<ItemGroup>

0 commit comments

Comments
 (0)