feat: Implement -a -A and -d flags

This commit is contained in:
NaiJi ✨ 2023-01-31 11:11:48 +04:00
parent dea3f1bd67
commit f88268caf7
2 changed files with 86 additions and 0 deletions

View File

@ -47,6 +47,35 @@ ParseResult extract(final List<String> args) {
currentStage = stageResult.stage;
result = stageResult.result;
break;
case ParsingStage.album:
final stageResult = _onEntityStage(
arg,
result,
currentStage,
FunkEntity.album,
);
currentStage = stageResult.stage;
result = stageResult.result;
break;
case ParsingStage.artist:
final stageResult = _onEntityStage(
arg,
result,
currentStage,
FunkEntity.artist,
);
currentStage = stageResult.stage;
result = stageResult.result;
break;
case ParsingStage.domain:
final stageResult = _onDomainStage(arg, result, currentStage);
currentStage = stageResult.stage;
result = stageResult.result;
break;
default:
console.error('not implemented yet');
break;
@ -56,6 +85,58 @@ ParseResult extract(final List<String> args) {
return result;
}
StageResult _onEntityStage(
final String arg,
final ParseResult previousResult,
final ParsingStage previousStage,
final FunkEntity kind,
) {
ParsingStage currentStage = previousStage;
ParseResult result = previousResult;
if (int.tryParse(arg) != null) {
currentStage = ParsingStage.nothing;
result = ParseResult(
action: previousResult.action,
success: true,
object: FunkObject(
domain: previousResult.object?.domain ?? '',
id: arg,
kind: kind,
),
);
}
return StageResult(result: result, stage: currentStage);
}
StageResult _onDomainStage(
final String arg,
final ParseResult previousResult,
final ParsingStage previousStage,
) {
ParsingStage currentStage = previousStage;
ParseResult result = previousResult;
try {
final Uri uri = Uri.parse(arg);
currentStage = ParsingStage.nothing;
result = ParseResult(
action: previousResult.action,
success: true,
object: FunkObject(
domain: uri.toString(),
id: previousResult.object?.id ?? '',
kind: previousResult.object?.kind ?? FunkEntity.album,
),
);
} catch (e) {
console.error(e.toString());
}
return StageResult(result: result, stage: currentStage);
}
StageResult _onNothingStage(
final String arg,
final ParseResult previousResult,
@ -80,6 +161,10 @@ StageResult _onNothingStage(
case '--path':
currentStage = ParsingStage.path;
break;
case '-d':
case '--domain':
currentStage = ParsingStage.domain;
break;
default:
try {
final Uri uri = Uri.parse(arg);

View File

@ -5,4 +5,5 @@ enum ParsingStage {
song,
path,
upload,
domain,
}