mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Use CSharpier
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -49,21 +49,23 @@ public partial class BookAddCommand
|
||||
{
|
||||
private static readonly Random Random = new();
|
||||
|
||||
private static DateTimeOffset CreateRandomDate() => new(
|
||||
Random.Next(1800, 2020),
|
||||
Random.Next(1, 12),
|
||||
Random.Next(1, 28),
|
||||
Random.Next(1, 23),
|
||||
Random.Next(1, 59),
|
||||
Random.Next(1, 59),
|
||||
TimeSpan.Zero
|
||||
);
|
||||
private static DateTimeOffset CreateRandomDate() =>
|
||||
new(
|
||||
Random.Next(1800, 2020),
|
||||
Random.Next(1, 12),
|
||||
Random.Next(1, 28),
|
||||
Random.Next(1, 23),
|
||||
Random.Next(1, 59),
|
||||
Random.Next(1, 59),
|
||||
TimeSpan.Zero
|
||||
);
|
||||
|
||||
private static Isbn CreateRandomIsbn() => new(
|
||||
Random.Next(0, 999),
|
||||
Random.Next(0, 99),
|
||||
Random.Next(0, 99999),
|
||||
Random.Next(0, 99),
|
||||
Random.Next(0, 9)
|
||||
);
|
||||
}
|
||||
private static Isbn CreateRandomIsbn() =>
|
||||
new(
|
||||
Random.Next(0, 999),
|
||||
Random.Next(0, 99),
|
||||
Random.Next(0, 99999),
|
||||
Random.Next(0, 99),
|
||||
Random.Next(0, 9)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ public class BookCommand : ICommand
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,4 +33,4 @@ public class BookListCommand : ICommand
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,4 @@ public class BookRemoveCommand : ICommand
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
namespace CliFx.Demo.Domain;
|
||||
|
||||
public record Book(string Title, string Author, DateTimeOffset Published, Isbn Isbn);
|
||||
public record Book(string Title, string Author, DateTimeOffset Published, Isbn Isbn);
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
namespace CliFx.Demo.Domain;
|
||||
|
||||
public partial record Isbn(int EanPrefix, int RegistrationGroup, int Registrant, int Publication, int CheckDigit)
|
||||
public partial record Isbn(
|
||||
int EanPrefix,
|
||||
int RegistrationGroup,
|
||||
int Registrant,
|
||||
int Publication,
|
||||
int CheckDigit
|
||||
)
|
||||
{
|
||||
public override string ToString() =>
|
||||
$"{EanPrefix:000}-{RegistrationGroup:00}-{Registrant:00000}-{Publication:00}-{CheckDigit:0}";
|
||||
@@ -22,4 +28,4 @@ public partial record Isbn
|
||||
int.Parse(components[4], formatProvider)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,4 @@ public partial record Library(IReadOnlyList<Book> Books)
|
||||
public partial record Library
|
||||
{
|
||||
public static Library Empty { get; } = new(Array.Empty<Book>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace CliFx.Demo.Domain;
|
||||
|
||||
public class LibraryProvider
|
||||
{
|
||||
private static string StorageFilePath { get; } = Path.Combine(Directory.GetCurrentDirectory(), "Library.json");
|
||||
private static string StorageFilePath { get; } =
|
||||
Path.Combine(Directory.GetCurrentDirectory(), "Library.json");
|
||||
|
||||
private void StoreLibrary(Library library)
|
||||
{
|
||||
@@ -24,7 +25,8 @@ public class LibraryProvider
|
||||
return JsonSerializer.Deserialize<Library>(data) ?? Library.Empty;
|
||||
}
|
||||
|
||||
public Book? TryGetBook(string title) => GetLibrary().Books.FirstOrDefault(b => b.Title == title);
|
||||
public Book? TryGetBook(string title) =>
|
||||
GetLibrary().Books.FirstOrDefault(b => b.Title == title);
|
||||
|
||||
public void AddBook(Book book)
|
||||
{
|
||||
@@ -37,4 +39,4 @@ public class LibraryProvider
|
||||
var updatedLibrary = GetLibrary().WithoutBook(book);
|
||||
StoreLibrary(updatedLibrary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ return await new CliApplicationBuilder()
|
||||
return services.BuildServiceProvider();
|
||||
})
|
||||
.Build()
|
||||
.RunAsync();
|
||||
.RunAsync();
|
||||
|
||||
@@ -33,4 +33,4 @@ internal static class ConsoleExtensions
|
||||
using (writer.Console.WithForegroundColor(ConsoleColor.White))
|
||||
writer.WriteLine(book.Isbn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user