replaced dtsod with json
This commit is contained in:
@@ -4,67 +4,77 @@ global using DTLib.Demystifier;
|
||||
global using DTLib.Filesystem;
|
||||
global using Directory = DTLib.Filesystem.Directory;
|
||||
global using File = DTLib.Filesystem.File;
|
||||
using ParadoxSaveParser.CLI;
|
||||
|
||||
try
|
||||
namespace ParadoxSaveParser.CLI;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
Mode mode = Mode.Unset;
|
||||
IOPath? inputPath = null;
|
||||
IOPath? outputPath = null;
|
||||
string? searchQuery = null;
|
||||
|
||||
new LaunchArgumentParser(
|
||||
new LaunchArgument(["i", "input"],
|
||||
"Set input file path",
|
||||
s => inputPath = s,
|
||||
"gamestate or zip file"),
|
||||
|
||||
new LaunchArgument(["o", "output"],
|
||||
"Set output file path",
|
||||
s => outputPath = s,
|
||||
"json file [default=stdout]"),
|
||||
|
||||
new LaunchArgument(["s", "search"],
|
||||
"Search in input file",
|
||||
s =>
|
||||
{
|
||||
searchQuery = s;
|
||||
mode = Mode.Search;
|
||||
},
|
||||
"search expression")
|
||||
)
|
||||
.AllowNoArguments()
|
||||
.ParseAndHandle(args);
|
||||
|
||||
if (args.Length == 0)
|
||||
mode = Mode.Interactive;
|
||||
|
||||
switch (mode)
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(mode));
|
||||
case Mode.Unset:
|
||||
throw new Exception("No action specified");
|
||||
case Mode.Search:
|
||||
if (string.IsNullOrEmpty(searchQuery))
|
||||
throw new ArgumentException("Search expression is required");
|
||||
if (inputPath is null)
|
||||
throw new ArgumentException("Input file path is required");
|
||||
Modes.Search(searchQuery, inputPath.Value, outputPath);
|
||||
break;
|
||||
case Mode.Interactive:
|
||||
Modes.Interactive();
|
||||
break;
|
||||
try
|
||||
{
|
||||
Mode mode = Mode.Unset;
|
||||
IOPath? inputPath = null;
|
||||
IOPath? outputPath = null;
|
||||
string? searchQuery = null;
|
||||
|
||||
new LaunchArgumentParser(
|
||||
new LaunchArgument(["i", "input"],
|
||||
"Set input file path",
|
||||
s => inputPath = s,
|
||||
"gamestate or zip file"),
|
||||
|
||||
new LaunchArgument(["o", "output"],
|
||||
"Set output file path",
|
||||
s => outputPath = s,
|
||||
"json file [default=stdout]"),
|
||||
|
||||
new LaunchArgument(["s", "search"],
|
||||
"Search in input file",
|
||||
s =>
|
||||
{
|
||||
searchQuery = s;
|
||||
mode = Mode.Search;
|
||||
},
|
||||
"search expression")
|
||||
)
|
||||
.AllowNoArguments()
|
||||
.ParseAndHandle(args);
|
||||
|
||||
if (args.Length == 0)
|
||||
mode = Mode.Interactive;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(mode));
|
||||
case Mode.Unset:
|
||||
throw new Exception("No action specified");
|
||||
case Mode.Search:
|
||||
if (string.IsNullOrEmpty(searchQuery))
|
||||
throw new ArgumentException("Search expression is required");
|
||||
if (inputPath is null)
|
||||
throw new ArgumentException("Input file path is required");
|
||||
Modes.Search(searchQuery, inputPath.Value, outputPath);
|
||||
break;
|
||||
case Mode.Interactive:
|
||||
Modes.Interactive();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (LaunchArgumentParser.ExitAfterHelpException)
|
||||
{
|
||||
// this exception is throwed after -h argument to close the program
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ColoredConsole.WriteLine(ex.ToStringDemystified(), ConsoleColor.Red);
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.ResetColor();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (LaunchArgumentParser.ExitAfterHelpException)
|
||||
{
|
||||
// this exception is throwed after -h argument to close the program
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ColoredConsole.WriteLine(ex.ToStringDemystified(), ConsoleColor.Red);
|
||||
Console.ResetColor();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
Console.ResetColor();
|
||||
}
|
||||
Reference in New Issue
Block a user