Created the Avalonia MVVM template, split the CLI into Avalonia.UI and Avalonia.Core

This commit is contained in:
2023-08-07 20:37:02 +05:30
parent 6b989db91b
commit 1e6ac3b1fc
22 changed files with 464 additions and 20 deletions

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutumnLauncher.Core\AutumnLauncher.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,73 @@
using CommandLine;
namespace AutumnLauncher.CLI;
// Command-line options for the --run argument
[Verb("run", HelpText = "Run a game.")]
public class RunOptions
{
[Option('i', "id", Required = true, HelpText = "Game ID.")]
public int Id { get; set; }
}
// Command-line options for the --remove argument
[Verb("remove", HelpText = "Remove a game.")]
public class RemoveOptions
{
[Option('i', "id", Required = true, HelpText = "Game ID.")]
public int Id { get; set; }
}
// Command-line options for the --list argument
[Verb("list", HelpText = "List all games.")]
public class ListOptions
{
}
// Command-line options for the --add argument
[Verb("add", HelpText = "Add a game.")]
public class AddOptions
{
[Option('n', "name", Required = true, HelpText = "Game name.")]
public string? Name { get; set; }
[Option('d', "developer", Required = true, HelpText = "Game developer.")]
public string? Developer { get; set; }
[Option('r', "date", Required = true, HelpText = "Release date.")]
public string? Date { get; set; }
[Option('g', "genre", Required = true, HelpText = "Game genre.")]
public string? Genre { get; set; }
[Option('t', "type", Required = true, HelpText = "Game type.")]
public string? Type { get; set; }
[Option('p', "path", Required = true, HelpText = "Game path.")]
public string? Path { get; set; }
}
[Verb("edit", HelpText = "Add a game.")]
public class EditOptions
{
[Option('i', "id", Required = true, HelpText = "Game id.")]
public int Id { get; set; }
[Option('n', "name", Required = false, HelpText = "Game name.")]
public string? Name { get; set; }
[Option('d', "developer", Required = false, HelpText = "Game developer.")]
public string? Developer { get; set; }
[Option('r', "date", Required = false, HelpText = "Release date.")]
public string? Date { get; set; }
[Option('g', "genre", Required = false, HelpText = "Game genre.")]
public string? Genre { get; set; }
[Option('t', "type", Required = false, HelpText = "Game type.")]
public string? Type { get; set; }
[Option('p', "path", Required = false, HelpText = "Game path.")]
public string? Path { get; set; }
}

View File

@@ -0,0 +1,53 @@
using CommandLine;
namespace AutumnLauncher.CLI;
public static class Program
{
public static void Main(string[] args)
{
// create directory and database if not already created
Directory.CreateDirectory(Configuration.DataDir);
Directory.CreateDirectory(Configuration.ConfigDir);
SqliteData.CreateDatabase();
Parser.Default.ParseArguments<AddOptions, ListOptions, RunOptions, RemoveOptions, EditOptions>(args)
.WithParsed<AddOptions>(RunAdd)
.WithParsed<ListOptions>(RunList)
.WithParsed<RemoveOptions>(RunRemove)
.WithParsed<RunOptions>(RunRun)
.WithParsed<EditOptions>(RunEdit);
//.WithNotParsed(HandleParseError);
}
private static void RunAdd(AddOptions options)
{
ControlActions.Add(options.Name, options.Developer, options.Date, options.Genre, options.Type, options.Path);
}
private static void RunList(ListOptions options)
{
ControlActions.List();
}
private static void RunRemove(RemoveOptions options)
{
ControlActions.Remove(options.Id);
}
private static void RunRun(RunOptions options)
{
ControlActions.Run(options.Id);
}
private static void RunEdit(EditOptions options)
{
ControlActions.Edit(options.Id, options.Name, options.Developer, options.Date, options.Genre, options.Type, options.Path);
}
// private static void HandleParseError(IEnumerable<Error> errors)
// {
// // Handle command-line argument parsing errors
// foreach (var error in errors) Console.WriteLine(error.ToString());
// }
}