-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make format of arguments more flexible
- Loading branch information
1 parent
f6b8996
commit df99cd0
Showing
10 changed files
with
143 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Zack.DotNetTrimmerLib; | ||
|
||
namespace Zack.DotNetTrimmer | ||
{ | ||
static class CmdLineArgsParser | ||
{ | ||
public static TimmerOptions Parse(string[] args) | ||
{ | ||
//--greedy --record d:/1.json --file d:/1.exe | ||
//--record d:/1.json --greedy --file d:/1.exe a b | ||
//--greedy --file d:/1.exe a b | ||
//--file d:/1.exe | ||
//--apply d:/1.json --greedy --file d:/1.exe | ||
TimmerOptions options = new TimmerOptions(); | ||
int greedyIndex = FindArgIndex(args, "--greedy"); | ||
options.Greedy = greedyIndex >= 0; | ||
int recordIndex = FindArgIndex(args, "--record"); | ||
int applyIndex = FindArgIndex(args, "--apply"); | ||
if (recordIndex >= 0) | ||
{ | ||
options.Mode = TrimmingMode.Record; | ||
options.RecordFileName = args[recordIndex + 1]; | ||
} | ||
else if (applyIndex >= 0) | ||
{ | ||
options.Mode = TrimmingMode.Apply; | ||
options.RecordFileName = args[applyIndex + 1]; | ||
} | ||
else | ||
{ | ||
options.Mode = TrimmingMode.Direct; | ||
} | ||
int fileIndex = FindArgIndex(args, "--file"); | ||
if (fileIndex >= 0) | ||
{ | ||
options.StartupFile = args[fileIndex + 1]; | ||
options.Arguments = args.Skip(fileIndex + 1).ToArray(); | ||
} | ||
return options; | ||
} | ||
|
||
static int FindArgIndex(string[] args, string value) | ||
{ | ||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
if (args[i].Equals(value, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Text.Json; | ||
|
||
namespace Zack.DotNetTrimmerLib | ||
{ | ||
static class JsonHelper | ||
{ | ||
public static void SaveAsFile(string file, object value) | ||
{ | ||
JsonSerializerOptions jsonOpt = new() { WriteIndented = true }; | ||
using FileStream fileStream = File.Open(file, FileMode.Create); | ||
JsonSerializer.Serialize(fileStream, value, jsonOpt); | ||
} | ||
|
||
public static T LoadFromFile<T>(string file) | ||
{ | ||
using FileStream fileStream = File.OpenRead(file); | ||
var obj = JsonSerializer.Deserialize<T>(File.ReadAllText(file)); | ||
if (obj == null) | ||
{ | ||
throw new IOException("loading error"); | ||
} | ||
else | ||
{ | ||
return obj; | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.