From 22fb257af9d902920e6ec5a2ad12561431ce4a12 Mon Sep 17 00:00:00 2001 From: Gorniaky Date: Tue, 7 Jul 2026 17:06:23 -0300 Subject: [PATCH 1/2] refactor(commands): update option handling for app and dir parameters --- lib/commands/app/backup.dart | 2 +- lib/commands/app/commit.dart | 13 ++++---- lib/commands/team/backup.dart | 3 +- lib/commands/team/commit.dart | 13 ++++---- lib/commands/zip.dart | 2 +- lib/extensions/arg_results.dart | 58 +++++++++++++++------------------ 6 files changed, 44 insertions(+), 47 deletions(-) diff --git a/lib/commands/app/backup.dart b/lib/commands/app/backup.dart index 15e9a58..29f2e87 100644 --- a/lib/commands/app/backup.dart +++ b/lib/commands/app/backup.dart @@ -60,7 +60,7 @@ final class AppBackupCommand extends Command with Disposable { Future _handleSingle(Map data, ISpin spinner) async { if (data["url"] case final String url) { - if (argResults!.optionOrRest("dir", ["app"]) case final dir) { + if (argResults!.optionOrRest("dir", ["app"]) case final dir?) { final Uri uri = .parse(url); return _download(dir: dir, spinner: spinner, uri: uri); diff --git a/lib/commands/app/commit.dart b/lib/commands/app/commit.dart index 4de7024..5d55e6b 100644 --- a/lib/commands/app/commit.dart +++ b/lib/commands/app/commit.dart @@ -39,15 +39,16 @@ final class AppCommitCommand extends Command with Disposable { Future run() async { final directory = context.workspaceFolder; - final optionAppId = argResults!.option("app"); - final appId = - optionAppId ?? - argResults?.rest.firstOrNull ?? - await _getDiscloudConfigAppId(directory); + final optionAppId = argResults?.optionOrRest("app"); + final appId = optionAppId ?? await _getDiscloudConfigAppId(directory); if (appId == null) throw Exception("Missing app id"); - final glob = argResults?.multiOptionOrRest("glob", [if (optionAppId != null) "app"]) ?? const ["**"]; + final glob = + argResults?.multiOptionOrRest("glob", [ + if (optionAppId != null) "app", + ]) ?? + const ["**"]; final spinner = context.printer.spin(text: "Zipping..."); diff --git a/lib/commands/team/backup.dart b/lib/commands/team/backup.dart index 4f6c9e7..8c2ad19 100644 --- a/lib/commands/team/backup.dart +++ b/lib/commands/team/backup.dart @@ -41,7 +41,6 @@ final class TeamBackupCommand extends Command with Disposable { @override Future run() async { final appId = argResults!.optionOrRest("app") ?? "all"; - final dir = argResults!.optionOrRest("dir", ["app"]); final spinner = context.printer.spin(text: "Fetching backup..."); @@ -61,7 +60,7 @@ final class TeamBackupCommand extends Command with Disposable { Future _handleSingle(Map data, ISpin spinner) async { if (data["url"] case final String url) { - if (argResults!.optionOrRest("dir", ["app"]) case final dir) { + if (argResults!.optionOrRest("dir", ["app"]) case final dir?) { final Uri uri = .parse(url); return _download(dir: dir, spinner: spinner, uri: uri); diff --git a/lib/commands/team/commit.dart b/lib/commands/team/commit.dart index 3fe2459..273590e 100644 --- a/lib/commands/team/commit.dart +++ b/lib/commands/team/commit.dart @@ -39,15 +39,16 @@ final class TeamCommitCommand extends Command with Disposable { Future run() async { final directory = context.workspaceFolder; - final optionAppId = argResults?.option("app"); - final appId = - optionAppId ?? - argResults?.rest.firstOrNull ?? - await _getDiscloudConfigAppId(directory); + final optionAppId = argResults?.optionOrRest("app"); + final appId = optionAppId ?? await _getDiscloudConfigAppId(directory); if (appId == null) throw Exception("Missing app id"); - final glob = argResults?.multiOptionOrRest("glob", [if (optionAppId != null) "app"]) ?? const ["**"]; + final glob = + argResults?.multiOptionOrRest("glob", [ + if (optionAppId != null) "app", + ]) ?? + const ["**"]; final spinner = context.printer.spin(text: "Zipping..."); diff --git a/lib/commands/zip.dart b/lib/commands/zip.dart index 0467c15..eb10a6a 100644 --- a/lib/commands/zip.dart +++ b/lib/commands/zip.dart @@ -14,7 +14,7 @@ final class ZipCommand extends Command with Disposable { ZipCommand() { argParser ..addOption("encoding", abbr: "e", allowed: const ["buffer"], hide: true) - ..addMultiOption("glob", abbr: "g", valueHelp: const ["**"]) + ..addMultiOption("glob", abbr: "g", valueHelp: "**") ..addOption("out", abbr: "o", help: "Zip output") ..addOption( "level", diff --git a/lib/extensions/arg_results.dart b/lib/extensions/arg_results.dart index e4cbc1d..71f0780 100644 --- a/lib/extensions/arg_results.dart +++ b/lib/extensions/arg_results.dart @@ -1,34 +1,13 @@ import "package:args/args.dart"; import "package:args/command_runner.dart"; -extension NullableArgResultsExtension on ArgResults? { - String? get commandName { - final list = []; - - ArgResults? command = this; - while (command != null) { - if (command.name case final name?) list.add(name); - command = command.command; - } - - if (list.isEmpty) return null; - - return list.join(" "); - } -} +const _whiteSpace = " "; extension ArgResultsExtension on ArgResults { - bool wasNotParsed(String name) { - return !wasParsed(name); - } - String? optionOrRest(String name, [Iterable after = const []]) { if (wasParsed(name)) return option(name); - final index = after.where(wasNotParsed).length; - if (rest.length > index) return rest[index]; - return null; } @@ -36,8 +15,7 @@ extension ArgResultsExtension on ArgResults { String name, [ Iterable after = const [], ]) { - final value = optionOrRest(name, after); - if (value != null) return value; + if (optionOrRest(name, after) case final value?) return value; throw UsageException("Missing required option or argument: $name", ""); } @@ -47,8 +25,7 @@ extension ArgResultsExtension on ArgResults { Iterable after = const [], ]) { final raw = requiredOptionOrRest(name, after); - final value = int.tryParse(raw); - if (value != null) return value; + if (int.tryParse(raw) case final value?) return value; throw UsageException("Invalid integer for $name: $raw", ""); } @@ -58,11 +35,8 @@ extension ArgResultsExtension on ArgResults { Iterable after = const [], ]) { if (wasParsed(name)) return multiOption(name); - final index = after.where(wasNotParsed).length; - if (rest.length > index) return rest.skip(index).toList(); - return null; } @@ -70,9 +44,31 @@ extension ArgResultsExtension on ArgResults { String name, [ Iterable after = const [], ]) { - final values = multiOptionOrRest(name, after); - if (values != null && values.isNotEmpty) return values; + if (multiOptionOrRest(name, after) case final values? + when values.isNotEmpty) { + return values; + } throw UsageException("Missing required option or argument: $name", ""); } + + bool wasNotParsed(String name) { + return !wasParsed(name); + } +} + +extension NullableArgResultsExtension on ArgResults? { + String? get commandName { + final list = []; + + ArgResults? command = this; + while (command != null) { + if (command.name case final name?) list.add(name); + command = command.command; + } + + if (list.isEmpty) return null; + + return list.join(_whiteSpace); + } } From 30bb6835732390c4ea6db125cc3e200d84021e32 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 7 Jul 2026 20:07:33 +0000 Subject: [PATCH 2/2] docs: update 22fb257 --- docs/commands.md | 148 +++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 3bbb9a4..31d9e17 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -47,9 +47,9 @@ Available subcommands: Install APT on your app Usage: discloud app apt install [arguments] --h, --help Print this usage information. - --app (mandatory) - --apt canvas,ffmpeg,java,libgl,mysql,openssl,puppeteer,selenium,tesseract,tools,unixodbc +-h, --help Print this usage information. + --app + --apt canvas,ffmpeg,java,libgl,mysql,openssl,puppeteer,selenium,tesseract,tools,unixodbc ``` ##### app apt uninstall @@ -58,9 +58,9 @@ Usage: discloud app apt install [arguments] Uninstall APT from your app Usage: discloud app apt uninstall [arguments] --h, --help Print this usage information. - --app (mandatory) - --apt canvas,ffmpeg,java,libgl,mysql,openssl,puppeteer,selenium,tesseract,tools,unixodbc +-h, --help Print this usage information. + --app + --apt canvas,ffmpeg,java,libgl,mysql,openssl,puppeteer,selenium,tesseract,tools,unixodbc ``` #### app backup @@ -69,9 +69,9 @@ Usage: discloud app apt uninstall [arguments] Get backup of your app code from Discloud Usage: discloud app backup [arguments] --h, --help Print this usage information. - --app= (mandatory) --d, --dir Specifies the destination path for downloading backups. The destination path will be considered a directory. +-h, --help Print this usage information. + --app= +-d, --dir Specifies the destination path for downloading backups. The destination path will be considered a directory. ``` #### app commit @@ -91,9 +91,9 @@ Usage: discloud app commit [arguments] Use the app terminal Usage: discloud app console [arguments] --h, --help Print this usage information. - --app (mandatory) - --command +-h, --help Print this usage information. + --app + --command ``` #### app delete @@ -102,9 +102,9 @@ Usage: discloud app console [arguments] Delete one of your apps on Discloud Usage: discloud app delete [arguments] --h, --help Print this usage information. --y, --yes Skip confirmation prompt - --app (mandatory) +-h, --help Print this usage information. +-y, --yes Skip confirmation prompt + --app ``` #### app info @@ -113,8 +113,8 @@ Usage: discloud app delete [arguments] Get information of your apps Usage: discloud app info [arguments] --h, --help Print this usage information. - --app (defaults to "all") +-h, --help Print this usage information. + --app= ``` #### app logs @@ -123,9 +123,9 @@ Usage: discloud app info [arguments] View the logs from application in Discloud Usage: discloud app logs [arguments] --h, --help Print this usage information. - --app= (mandatory) When set to 'all', this command will automatically download logs and will not display URLs. If the 'out' option is not set, downloads will be made to the current folder. - --out Specifies the destination path for downloading logs. When the application option is set to 'all', the destination path will be considered a directory where all downloads will be stored. +-h, --help Print this usage information. + --app= When set to 'all', this command will automatically download logs and will not display URLs. If the 'out' option is not set, downloads will be made to the current folder. + --out Specifies the destination path for downloading logs. When the application option is set to 'all', the destination path will be considered a directory where all downloads will be stored. ``` #### app mod @@ -149,10 +149,10 @@ Available subcommands: Add MOD to your app Usage: discloud app mod add [arguments] --h, --help Print this usage information. - --app (mandatory) - --mod (mandatory) - --perms [backup_app, commit_app, edit_ram, logs_app, restart_app, start_app, status_app, stop_app] +-h, --help Print this usage information. + --app + --mod + --perms [backup_app, commit_app, edit_ram, logs_app, restart_app, start_app, status_app, stop_app] ``` ##### app mod delete @@ -161,9 +161,9 @@ Usage: discloud app mod add [arguments] Delete MOD of your app Usage: discloud app mod delete [arguments] --h, --help Print this usage information. - --app (mandatory) - --mod (mandatory) +-h, --help Print this usage information. + --app + --mod ``` ##### app mod edit @@ -172,10 +172,10 @@ Usage: discloud app mod delete [arguments] Edit MOD perms of your app Usage: discloud app mod edit [arguments] --h, --help Print this usage information. - --app (mandatory) - --mod (mandatory) - --perms [backup_app, commit_app, edit_ram, logs_app, restart_app, start_app, status_app, stop_app] +-h, --help Print this usage information. + --app + --mod + --perms [backup_app, commit_app, edit_ram, logs_app, restart_app, start_app, status_app, stop_app] ``` ##### app mod info @@ -184,8 +184,8 @@ Usage: discloud app mod edit [arguments] Get MOD info of your app Usage: discloud app mod info [arguments] --h, --help Print this usage information. - --app (mandatory) +-h, --help Print this usage information. + --app ``` #### app profile @@ -194,10 +194,10 @@ Usage: discloud app mod info [arguments] Updates the profile information (avatar and name) for a specific app Usage: discloud app profile [arguments] --h, --help Print this usage information. - --app (mandatory) - --name - --avatar +-h, --help Print this usage information. + --app + --name + --avatar ``` #### app ram @@ -206,9 +206,9 @@ Usage: discloud app profile [arguments] Set amount of ram for your app Usage: discloud app ram [arguments] --h, --help Print this usage information. - --app (mandatory) - --amount=<100> (mandatory) +-h, --help Print this usage information. + --app + --amount=<100> ``` #### app restart @@ -237,8 +237,8 @@ Usage: discloud app start [arguments] Get status of your app Usage: discloud app status [arguments] --h, --help Print this usage information. - --app (mandatory) +-h, --help Print this usage information. + --app ``` #### app stop @@ -257,8 +257,8 @@ Usage: discloud app stop [arguments] Upload one app or site to Discloud Usage: discloud app upload [arguments] --h, --help Print this usage information. --g, --glob (defaults to "**") +-h, --help Print this usage information. +-g, --glob=<**> ``` ### domain @@ -283,9 +283,9 @@ Available subcommands: Create a domain Usage: discloud domain create [arguments] --h, --help Print this usage information. - --id (mandatory) - --app (mandatory) +-h, --help Print this usage information. + --id + --app ``` #### domain delete @@ -294,8 +294,8 @@ Usage: discloud domain create [arguments] Delete a domain Usage: discloud domain delete [arguments] --h, --help Print this usage information. - --id (mandatory) +-h, --help Print this usage information. + --id ``` #### domain edit @@ -304,9 +304,9 @@ Usage: discloud domain delete [arguments] Edit a domain Usage: discloud domain edit [arguments] --h, --help Print this usage information. - --id (mandatory) - --app (mandatory) +-h, --help Print this usage information. + --id + --app ``` #### domain info @@ -315,8 +315,8 @@ Usage: discloud domain edit [arguments] Get information of your domains Usage: discloud domain info [arguments] --h, --help Print this usage information. - --id (defaults to "all") +-h, --help Print this usage information. + --id= ``` #### domain verify @@ -325,8 +325,8 @@ Usage: discloud domain info [arguments] Verify a domain Usage: discloud domain verify [arguments] --h, --help Print this usage information. - --id (mandatory) +-h, --help Print this usage information. + --id ``` ### domain @@ -458,8 +458,8 @@ Available subcommands: Create a subdomain Usage: discloud subdomain create [arguments] --h, --help Print this usage information. - --id (mandatory) +-h, --help Print this usage information. + --id ``` #### subdomain delete @@ -468,8 +468,8 @@ Usage: discloud subdomain create [arguments] Delete a subdomain Usage: discloud subdomain delete [arguments] --h, --help Print this usage information. - --id (mandatory) +-h, --help Print this usage information. + --id ``` #### subdomain info @@ -478,8 +478,8 @@ Usage: discloud subdomain delete [arguments] Get information of your subdomains Usage: discloud subdomain info [arguments] --h, --help Print this usage information. - --id (defaults to "all") +-h, --help Print this usage information. + --id= ``` ### team @@ -508,9 +508,9 @@ Available subcommands: Get backup of your team app code from Discloud Usage: discloud team backup [arguments] --h, --help Print this usage information. - --app= (mandatory) --d, --dir Specifies the destination path for downloading backups. The destination path will be considered a directory. +-h, --help Print this usage information. + --app= +-d, --dir Specifies the destination path for downloading backups. The destination path will be considered a directory. ``` #### team commit @@ -540,9 +540,9 @@ Usage: discloud team info [arguments] View the logs from application in Discloud Usage: discloud team logs [arguments] --h, --help Print this usage information. - --app= (mandatory) When set to 'all', this command will automatically download logs and will not display URLs. If the 'out' option is not set, downloads will be made to the current folder. - --out Specifies the destination path for downloading logs. When the application option is set to 'all', the destination path will be considered a directory where all downloads will be stored. +-h, --help Print this usage information. + --app= When set to 'all', this command will automatically download logs and will not display URLs. If the 'out' option is not set, downloads will be made to the current folder. + --out Specifies the destination path for downloading logs. When the application option is set to 'all', the destination path will be considered a directory where all downloads will be stored. ``` #### team ram @@ -551,9 +551,9 @@ Usage: discloud team logs [arguments] Set amount of ram for your app Usage: discloud team ram [arguments] --h, --help Print this usage information. - --app (mandatory) - --amount=<100> (mandatory) +-h, --help Print this usage information. + --app + --amount=<100> ``` #### team restart @@ -582,8 +582,8 @@ Usage: discloud team start [arguments] Get status of your app Usage: discloud team status [arguments] --h, --help Print this usage information. - --app (mandatory) +-h, --help Print this usage information. + --app ``` #### team stop @@ -636,7 +636,7 @@ Make zip Usage: discloud zip [arguments] -h, --help Print this usage information. --g, --glob (defaults to "**") +-g, --glob=<**> -o, --out Zip output -l, --level=<0-9> Compression level -p, --password Zip password