From d8ddc8001a25d101d5bc56385c15efee18228c98 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 2 Feb 2023 01:00:23 +0400 Subject: [PATCH] feat: Add -p flag for explicit path --- bin/main.dart | 5 ++++- lib/funkblubber.dart | 2 +- lib/parsing/parser.dart | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index a26f977..599f02c 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -11,5 +11,8 @@ void main(final List arguments) async { return; } - await funkblubber.download(object: result.object!); + await funkblubber.download( + object: result.object!, + path: result.localPath ?? '.', + ); } diff --git a/lib/funkblubber.dart b/lib/funkblubber.dart index a04df19..f01678b 100644 --- a/lib/funkblubber.dart +++ b/lib/funkblubber.dart @@ -6,7 +6,7 @@ import 'package:funkblubber/console.dart' as console; Future download({ required final FunkObject object, - final String path = '.', + required final String path, }) async { console.info('Downloading'); switch (object.kind) { diff --git a/lib/parsing/parser.dart b/lib/parsing/parser.dart index 0786a0c..6fccd46 100644 --- a/lib/parsing/parser.dart +++ b/lib/parsing/parser.dart @@ -76,6 +76,12 @@ ParseResult extract(final List args) { result = stageResult.result; break; + case ParsingStage.path: + final stageResult = _onPathStage(arg, result, currentStage); + currentStage = stageResult.stage; + result = stageResult.result; + break; + default: console.error('not implemented yet'); break; @@ -137,6 +143,28 @@ StageResult _onDomainStage( return StageResult(result: result, stage: currentStage); } +String _cutTrailingDash(final String path) => + path.endsWith('/') ? path.substring(0, path.length - 1) : path; + +StageResult _onPathStage( + final String arg, + final ParseResult previousResult, + final ParsingStage previousStage, +) { + ParsingStage currentStage = previousStage; + ParseResult result = previousResult; + + currentStage = ParsingStage.nothing; + result = ParseResult( + localPath: _cutTrailingDash(arg), + action: previousResult.action, + success: true, + object: previousResult.object, + ); + + return StageResult(result: result, stage: currentStage); +} + StageResult _onNothingStage( final String arg, final ParseResult previousResult,