Account for a file path

This commit is contained in:
CheddarCrisp 2024-01-09 21:51:31 -05:00
parent ec0e0ec079
commit b7ebbd9169

View file

@ -1,7 +1,8 @@
SDBD.ICodec codec = new SDBD.Codec();
var (encode, filename) = ParseArgs(args);
var inputData = File.ReadAllBytes(filename);
var (encode, filepath) = ParseArgs(args);
var inputData = File.ReadAllBytes(filepath);
var filename = Path.GetFileName(filepath);
if(encode) {
SDBD.Document document = new (
@ -17,11 +18,11 @@ if(encode) {
File.WriteAllBytes(document.Metadata["content-name"], document.Data);
}
(bool encode, string filename) ParseArgs(string[] args) {
(bool encode, string filepath) ParseArgs(string[] args) {
return args switch {
[var filename] => (true, filename),
["-d", var filename] => (false, filename),
["-e", var filename] => (true, filename),
[var filepath] => (true, filepath),
["-d", var filepath] => (false, filepath),
["-e", var filepath] => (true, filepath),
_ => throw new Exception("I don't like those arguments")
};
}