1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2025-01-09 15:02:43 +00:00

clarify arg errors

This commit is contained in:
fiso64 2024-12-24 11:13:45 +01:00
parent 146066ebca
commit 7c428f84d5

View file

@ -637,7 +637,9 @@ public class Config
void setFlag(ref bool flag, ref int i, bool trueVal = true) void setFlag(ref bool flag, ref int i, bool trueVal = true)
{ {
if (i >= args.Count - 1 || args[i + 1].StartsWith('-')) if (i >= args.Count - 1 || args[i + 1].StartsWith('-'))
{
flag = trueVal; flag = trueVal;
}
else if (args[i + 1] == "false") else if (args[i + 1] == "false")
{ {
flag = !trueVal; flag = !trueVal;
@ -649,13 +651,17 @@ public class Config
i++; i++;
} }
else else
{
flag = trueVal; flag = trueVal;
} }
}
void setNullableFlag(ref bool? flag, ref int i, bool trueVal = true) void setNullableFlag(ref bool? flag, ref int i, bool trueVal = true)
{ {
if (i >= args.Count - 1 || args[i + 1].StartsWith('-')) if (i >= args.Count - 1 || args[i + 1].StartsWith('-'))
{
flag = trueVal; flag = trueVal;
}
else if (args[i + 1] == "false") else if (args[i + 1] == "false")
{ {
flag = !trueVal; flag = !trueVal;
@ -667,9 +673,18 @@ public class Config
i++; i++;
} }
else else
{
flag = trueVal; flag = trueVal;
} }
}
string getParameter(ref int i)
{
i++;
if (i < 0 || i >= args.Count)
throw new ArgumentException("Option requires parameter");
return args[i];
}
bool inputSet = false; bool inputSet = false;
@ -681,11 +696,11 @@ public class Config
{ {
case "-i": case "-i":
case "--input": case "--input":
input = args[++i]; input = getParameter(ref i);
break; break;
case "--it": case "--it":
case "--input-type": case "--input-type":
inputType = args[++i].ToLower().Trim() switch inputType = getParameter(ref i).ToLower().Trim() switch
{ {
"none" => InputType.None, "none" => InputType.None,
"csv" => InputType.CSV, "csv" => InputType.CSV,
@ -700,11 +715,11 @@ public class Config
case "-p": case "-p":
case "--path": case "--path":
case "--parent": case "--parent":
parentDir = args[++i]; parentDir = getParameter(ref i);
break; break;
case "-c": case "-c":
case "--config": case "--config":
confPath = args[++i]; confPath = getParameter(ref i);
break; break;
case "--nc": case "--nc":
case "--no-config": case "--no-config":
@ -712,7 +727,7 @@ public class Config
break; break;
case "--smd": case "--smd":
case "--skip-music-dir": case "--skip-music-dir":
skipMusicDir = args[++i]; skipMusicDir = getParameter(ref i);
break; break;
case "-g": case "-g":
case "--aggregate": case "--aggregate":
@ -720,7 +735,7 @@ public class Config
break; break;
case "--msa": case "--msa":
case "--min-shares-aggregate": case "--min-shares-aggregate":
minSharesAggregate = int.Parse(args[++i]); minSharesAggregate = int.Parse(getParameter(ref i));
break; break;
case "--rf": case "--rf":
case "--relax": case "--relax":
@ -729,37 +744,37 @@ public class Config
break; break;
case "--si": case "--si":
case "--spotify-id": case "--spotify-id":
spotifyId = args[++i]; spotifyId = getParameter(ref i);
break; break;
case "--ss": case "--ss":
case "--spotify-secret": case "--spotify-secret":
spotifySecret = args[++i]; spotifySecret = getParameter(ref i);
break; break;
case "--stk": case "--stk":
case "--spotify-token": case "--spotify-token":
spotifyToken = args[++i]; spotifyToken = getParameter(ref i);
break; break;
case "--str": case "--str":
case "--spotify-refresh": case "--spotify-refresh":
spotifyRefresh = args[++i]; spotifyRefresh = getParameter(ref i);
break; break;
case "--yk": case "--yk":
case "--youtube-key": case "--youtube-key":
ytKey = args[++i]; ytKey = getParameter(ref i);
break; break;
case "-l": case "-l":
case "--login": case "--login":
var login = args[++i].Split(';', 2); var login = getParameter(ref i).Split(';', 2);
username = login[0]; username = login[0];
password = login[1]; password = login[1];
break; break;
case "--user": case "--user":
case "--username": case "--username":
username = args[++i]; username = getParameter(ref i);
break; break;
case "--pass": case "--pass":
case "--password": case "--password":
password = args[++i]; password = getParameter(ref i);
break; break;
case "--rl": case "--rl":
case "--random-login": case "--random-login":
@ -767,55 +782,55 @@ public class Config
break; break;
case "--ac": case "--ac":
case "--artist-col": case "--artist-col":
artistCol = args[++i]; artistCol = getParameter(ref i);
break; break;
case "--tc": case "--tc":
case "--track-col": case "--track-col":
case "--title-col": case "--title-col":
titleCol = args[++i]; titleCol = getParameter(ref i);
break; break;
case "--alc": case "--alc":
case "--album-col": case "--album-col":
albumCol = args[++i]; albumCol = getParameter(ref i);
break; break;
case "--ydc": case "--ydc":
case "--yt-desc-col": case "--yt-desc-col":
descCol = args[++i]; descCol = getParameter(ref i);
break; break;
case "--atcc": case "--atcc":
case "--album-track-count-col": case "--album-track-count-col":
trackCountCol = args[++i]; trackCountCol = getParameter(ref i);
break; break;
case "--yic": case "--yic":
case "--yt-id-col": case "--yt-id-col":
ytIdCol = args[++i]; ytIdCol = getParameter(ref i);
break; break;
case "--lc": case "--lc":
case "--length-col": case "--length-col":
lengthCol = args[++i]; lengthCol = getParameter(ref i);
break; break;
case "--tf": case "--tf":
case "--time-format": case "--time-format":
timeUnit = args[++i]; timeUnit = getParameter(ref i);
break; break;
case "-n": case "-n":
case "--number": case "--number":
maxTracks = int.Parse(args[++i]); maxTracks = int.Parse(getParameter(ref i));
break; break;
case "-o": case "-o":
case "--offset": case "--offset":
offset = int.Parse(args[++i]); offset = int.Parse(getParameter(ref i));
break; break;
case "--nf": case "--nf":
case "--name-format": case "--name-format":
nameFormat = args[++i]; nameFormat = getParameter(ref i);
break; break;
case "--irs": case "--irs":
case "--invalid-replace-str": case "--invalid-replace-str":
invalidReplaceStr = args[++i]; invalidReplaceStr = getParameter(ref i);
break; break;
case "--print": case "--print":
printOption = args[++i].ToLower().Trim() switch printOption = getParameter(ref i).ToLower().Trim() switch
{ {
"none" => PrintOption.None, "none" => PrintOption.None,
"tracks" => PrintOption.Tracks, "tracks" => PrintOption.Tracks,
@ -882,7 +897,7 @@ public class Config
break; break;
case "--re": case "--re":
case "--regex": case "--regex":
string s = args[++i].Replace("\\;", "<<semicol>>"); string s = getParameter(ref i).Replace("\\;", "<<semicol>>");
string applyTo = "TAL"; string applyTo = "TAL";
if (s.Length > 2 && s[1] == ':' && (s[0] == 'T' || s[0] == 'A' || s[0] == 'L')) if (s.Length > 2 && s[1] == ':' && (s[0] == 'T' || s[0] == 'A' || s[0] == 'L'))
@ -921,7 +936,7 @@ public class Config
break; break;
case "--pp": case "--pp":
case "--playlist-path": case "--playlist-path":
m3uFilePath = args[++i]; m3uFilePath = getParameter(ref i);
break; break;
case "--nwi": case "--nwi":
case "--no-write-index": case "--no-write-index":
@ -931,46 +946,46 @@ public class Config
case "--ip": case "--ip":
case "--index-path": case "--index-path":
hasConfiguredIndex = true; hasConfiguredIndex = true;
indexFilePath = args[++i]; indexFilePath = getParameter(ref i);
break; break;
case "--lp": case "--lp":
case "--port": case "--port":
case "--listen-port": case "--listen-port":
listenPort = int.Parse(args[++i]); listenPort = int.Parse(getParameter(ref i));
break; break;
case "--st": case "--st":
case "--search-time": case "--search-time":
case "--search-timeout": case "--search-timeout":
searchTimeout = int.Parse(args[++i]); searchTimeout = int.Parse(getParameter(ref i));
break; break;
case "--Mst": case "--Mst":
case "--stale-time": case "--stale-time":
case "--max-stale-time": case "--max-stale-time":
maxStaleTime = int.Parse(args[++i]); maxStaleTime = int.Parse(getParameter(ref i));
break; break;
case "--cp": case "--cp":
case "--cd": case "--cd":
case "--processes": case "--processes":
case "--concurrent-processes": case "--concurrent-processes":
case "--concurrent-downloads": case "--concurrent-downloads":
concurrentProcesses = int.Parse(args[++i]); concurrentProcesses = int.Parse(getParameter(ref i));
break; break;
case "--spt": case "--spt":
case "--searches-per-time": case "--searches-per-time":
searchesPerTime = int.Parse(args[++i]); searchesPerTime = int.Parse(getParameter(ref i));
break; break;
case "--srt": case "--srt":
case "--searches-renew-time": case "--searches-renew-time":
searchRenewTime = int.Parse(args[++i]); searchRenewTime = int.Parse(getParameter(ref i));
break; break;
case "--Mr": case "--Mr":
case "--retries": case "--retries":
case "--max-retries": case "--max-retries":
maxRetriesPerTrack = int.Parse(args[++i]); maxRetriesPerTrack = int.Parse(getParameter(ref i));
break; break;
case "--atc": case "--atc":
case "--album-track-count": case "--album-track-count":
string a = args[++i]; string a = getParameter(ref i);
if (a == "-1") if (a == "-1")
{ {
minAlbumTrackCount = -1; minAlbumTrackCount = -1;
@ -992,11 +1007,11 @@ public class Config
break; break;
case "--matc": case "--matc":
case "--min-album-track-count": case "--min-album-track-count":
minAlbumTrackCount = int.Parse(args[++i]); minAlbumTrackCount = int.Parse(getParameter(ref i));
break; break;
case "--Matc": case "--Matc":
case "--max-album-track-count": case "--max-album-track-count":
maxAlbumTrackCount = int.Parse(args[++i]); maxAlbumTrackCount = int.Parse(getParameter(ref i));
break; break;
case "--eMtc": case "--eMtc":
case "--extract-max-track-count": case "--extract-max-track-count":
@ -1008,7 +1023,7 @@ public class Config
break; break;
case "--aa": case "--aa":
case "--album-art": case "--album-art":
albumArtOption = args[++i].ToLower().Trim() switch albumArtOption = getParameter(ref i).ToLower().Trim() switch
{ {
"default" => AlbumArtOption.Default, "default" => AlbumArtOption.Default,
"largest" => AlbumArtOption.Largest, "largest" => AlbumArtOption.Largest,
@ -1027,7 +1042,7 @@ public class Config
break; break;
case "--fap": case "--fap":
case "--failed-album-path": case "--failed-album-path":
failedAlbumPath = args[++i]; failedAlbumPath = getParameter(ref i);
break; break;
case "-t": case "-t":
case "--interactive": case "--interactive":
@ -1036,37 +1051,37 @@ public class Config
case "--pf": case "--pf":
case "--paf": case "--paf":
case "--pref-format": case "--pref-format":
preferredCond.Formats = args[++i].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); preferredCond.Formats = getParameter(ref i).Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
break; break;
case "--plt": case "--plt":
case "--pref-tolerance": case "--pref-tolerance":
case "--pref-length-tol": case "--pref-length-tol":
case "--pref-length-tolerance": case "--pref-length-tolerance":
preferredCond.LengthTolerance = int.Parse(args[++i]); preferredCond.LengthTolerance = int.Parse(getParameter(ref i));
break; break;
case "--pmbr": case "--pmbr":
case "--pref-min-bitrate": case "--pref-min-bitrate":
preferredCond.MinBitrate = int.Parse(args[++i]); preferredCond.MinBitrate = int.Parse(getParameter(ref i));
break; break;
case "--pMbr": case "--pMbr":
case "--pref-max-bitrate": case "--pref-max-bitrate":
preferredCond.MaxBitrate = int.Parse(args[++i]); preferredCond.MaxBitrate = int.Parse(getParameter(ref i));
break; break;
case "--pmsr": case "--pmsr":
case "--pref-min-samplerate": case "--pref-min-samplerate":
preferredCond.MinSampleRate = int.Parse(args[++i]); preferredCond.MinSampleRate = int.Parse(getParameter(ref i));
break; break;
case "--pMsr": case "--pMsr":
case "--pref-max-samplerate": case "--pref-max-samplerate":
preferredCond.MaxSampleRate = int.Parse(args[++i]); preferredCond.MaxSampleRate = int.Parse(getParameter(ref i));
break; break;
case "--pmbd": case "--pmbd":
case "--pref-min-bitdepth": case "--pref-min-bitdepth":
preferredCond.MinBitDepth = int.Parse(args[++i]); preferredCond.MinBitDepth = int.Parse(getParameter(ref i));
break; break;
case "--pMbd": case "--pMbd":
case "--pref-max-bitdepth": case "--pref-max-bitdepth":
preferredCond.MaxBitDepth = int.Parse(args[++i]); preferredCond.MaxBitDepth = int.Parse(getParameter(ref i));
break; break;
case "--pst": case "--pst":
case "--pstt": case "--pstt":
@ -1087,41 +1102,41 @@ public class Config
break; break;
case "--pbu": case "--pbu":
case "--pref-banned-users": case "--pref-banned-users":
preferredCond.BannedUsers = args[++i].Split(','); preferredCond.BannedUsers = getParameter(ref i).Split(',');
break; break;
case "--af": case "--af":
case "--format": case "--format":
necessaryCond.Formats = args[++i].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); necessaryCond.Formats = getParameter(ref i).Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
break; break;
case "--lt": case "--lt":
case "--tolerance": case "--tolerance":
case "--length-tol": case "--length-tol":
case "--length-tolerance": case "--length-tolerance":
necessaryCond.LengthTolerance = int.Parse(args[++i]); necessaryCond.LengthTolerance = int.Parse(getParameter(ref i));
break; break;
case "--mbr": case "--mbr":
case "--min-bitrate": case "--min-bitrate":
necessaryCond.MinBitrate = int.Parse(args[++i]); necessaryCond.MinBitrate = int.Parse(getParameter(ref i));
break; break;
case "--Mbr": case "--Mbr":
case "--max-bitrate": case "--max-bitrate":
necessaryCond.MaxBitrate = int.Parse(args[++i]); necessaryCond.MaxBitrate = int.Parse(getParameter(ref i));
break; break;
case "--msr": case "--msr":
case "--min-samplerate": case "--min-samplerate":
necessaryCond.MinSampleRate = int.Parse(args[++i]); necessaryCond.MinSampleRate = int.Parse(getParameter(ref i));
break; break;
case "--Msr": case "--Msr":
case "--max-samplerate": case "--max-samplerate":
necessaryCond.MaxSampleRate = int.Parse(args[++i]); necessaryCond.MaxSampleRate = int.Parse(getParameter(ref i));
break; break;
case "--mbd": case "--mbd":
case "--min-bitdepth": case "--min-bitdepth":
necessaryCond.MinBitDepth = int.Parse(args[++i]); necessaryCond.MinBitDepth = int.Parse(getParameter(ref i));
break; break;
case "--Mbd": case "--Mbd":
case "--max-bitdepth": case "--max-bitdepth":
necessaryCond.MaxBitDepth = int.Parse(args[++i]); necessaryCond.MaxBitDepth = int.Parse(getParameter(ref i));
break; break;
case "--stt": case "--stt":
case "--strict-title": case "--strict-title":
@ -1137,7 +1152,7 @@ public class Config
break; break;
case "--bu": case "--bu":
case "--banned-users": case "--banned-users":
necessaryCond.BannedUsers = args[++i].Split(','); necessaryCond.BannedUsers = getParameter(ref i).Split(',');
break; break;
case "--anl": case "--anl":
case "--accept-no-length": case "--accept-no-length":
@ -1145,12 +1160,12 @@ public class Config
break; break;
case "--cond": case "--cond":
case "--conditions": case "--conditions":
necessaryCond.AddConditions(ParseConditions(args[++i])); necessaryCond.AddConditions(ParseConditions(getParameter(ref i)));
break; break;
case "--pc": case "--pc":
case "--pref": case "--pref":
case "--preferred-conditions": case "--preferred-conditions":
preferredCond.AddConditions(ParseConditions(args[++i])); preferredCond.AddConditions(ParseConditions(getParameter(ref i)));
break; break;
case "--nmsc": case "--nmsc":
case "--no-modify-share-count": case "--no-modify-share-count":
@ -1166,7 +1181,7 @@ public class Config
break; break;
case "--smod": case "--smod":
case "--skip-mode-output-dir": case "--skip-mode-output-dir":
skipMode = args[++i].ToLower().Trim() switch skipMode = getParameter(ref i).ToLower().Trim() switch
{ {
"name" => SkipMode.Name, "name" => SkipMode.Name,
"tag" => SkipMode.Tag, "tag" => SkipMode.Tag,
@ -1176,7 +1191,7 @@ public class Config
break; break;
case "--smmd": case "--smmd":
case "--skip-mode-music-dir": case "--skip-mode-music-dir":
skipModeMusicDir = args[++i].ToLower().Trim() switch skipModeMusicDir = getParameter(ref i).ToLower().Trim() switch
{ {
"name" => SkipMode.Name, "name" => SkipMode.Name,
"tag" => SkipMode.Tag, "tag" => SkipMode.Tag,
@ -1197,11 +1212,11 @@ public class Config
break; break;
case "--fsd": case "--fsd":
case "--fast-search-delay": case "--fast-search-delay":
fastSearchDelay = int.Parse(args[++i]); fastSearchDelay = int.Parse(getParameter(ref i));
break; break;
case "--fsmus": case "--fsmus":
case "--fast-search-min-up-speed": case "--fast-search-min-up-speed":
fastSearchMinUpSpeed = double.Parse(args[++i]); fastSearchMinUpSpeed = double.Parse(getParameter(ref i));
break; break;
case "--debug": case "--debug":
setFlag(ref debugInfo, ref i); setFlag(ref debugInfo, ref i);
@ -1214,7 +1229,7 @@ public class Config
break; break;
case "--yda": case "--yda":
case "--yt-dlp-argument": case "--yt-dlp-argument":
ytdlpArgument = args[++i]; ytdlpArgument = getParameter(ref i);
break; break;
case "-a": case "-a":
case "--album": case "--album":
@ -1222,22 +1237,22 @@ public class Config
break; break;
case "--oc": case "--oc":
case "--on-complete": case "--on-complete":
onComplete = args[++i]; onComplete = getParameter(ref i);
break; break;
case "--ftd": case "--ftd":
case "--fails-to-downrank": case "--fails-to-downrank":
downrankOn = -int.Parse(args[++i]); downrankOn = -int.Parse(getParameter(ref i));
break; break;
case "--fti": case "--fti":
case "--fails-to-ignore": case "--fails-to-ignore":
ignoreOn = -int.Parse(args[++i]); ignoreOn = -int.Parse(getParameter(ref i));
break; break;
case "--uer": case "--uer":
case "--unknown-error-retries": case "--unknown-error-retries":
unknownErrorRetries = int.Parse(args[++i]); unknownErrorRetries = int.Parse(getParameter(ref i));
break; break;
case "--profile": case "--profile":
profile = args[++i]; profile = getParameter(ref i);
break; break;
case "--nbf": case "--nbf":
case "--no-browse-folder": case "--no-browse-folder":
@ -1253,7 +1268,7 @@ public class Config
break; break;
case "--alt": case "--alt":
case "--aggregate-length-tol": case "--aggregate-length-tol":
aggregateLengthTol = int.Parse(args[++i]); aggregateLengthTol = int.Parse(getParameter(ref i));
break; break;
case "--aps": case "--aps":
case "--album-parallel-search": case "--album-parallel-search":
@ -1261,7 +1276,7 @@ public class Config
break; break;
case "--apsc": case "--apsc":
case "--album-parallel-search-count": case "--album-parallel-search-count":
parallelAlbumSearchProcesses = int.Parse(args[++i]); parallelAlbumSearchProcesses = int.Parse(getParameter(ref i));
break; break;
default: default:
throw new ArgumentException($"Unknown argument: {args[i]}"); throw new ArgumentException($"Unknown argument: {args[i]}");