Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Use the app terminal
Usage: discloud app console [arguments]
-h, --help Print this usage information.
--app
--command
-c, --command
```

#### app delete
Expand Down Expand Up @@ -196,8 +196,8 @@ Updates the profile information (avatar and name) for a specific app
Usage: discloud app profile [arguments]
-h, --help Print this usage information.
--app
--name
--avatar
-n, --name
-a, --avatar
```

#### app ram
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/app/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class AppBackupCommand extends Command<void> with Disposable {

Future<void> _handleMulti(List list, ISpin spinner) async {
final client = _client = .new();
final dir = argResults?.optionOrRest("dir") ?? ".";
final dir = argResults!.optionOrRest("dir") ?? ".";

for (final data in list) {
final String appId = data["id"];
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/app/commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ final class AppCommitCommand extends Command<void> with Disposable {
Future<void> run() async {
final directory = context.workspaceFolder;

final optionAppId = argResults?.optionOrRest("app");
final optionAppId = argResults!.optionOrRest("app");
final appId = optionAppId ?? await _getDiscloudConfigAppId(directory);

if (appId == null) throw Exception("Missing app id");

final glob =
argResults?.multiOptionOrRest("glob", [
argResults!.multiOptionOrRest("glob", [
if (optionAppId != null) "app",
]) ??
const ["**"];
Expand Down
56 changes: 27 additions & 29 deletions lib/commands/app/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import "package:discloud/cli/spin/ispin.dart";
import "package:discloud/extensions/command.dart";
import "package:discloud/services/discloud/exception.dart";
import "package:discloud/utils/messages.dart";
import "package:tint/tint.dart";

const _commandPrefix = "\x1B[2m?> \x1B[22m";
const _exitCommand = "exit";

final class AppConsoleCommand extends Command<void> {
AppConsoleCommand() {
argParser
..addOption("app")
..addOption("command");
..addMultiOption("command", abbr: "c");
}

@override
Expand All @@ -27,33 +29,30 @@ final class AppConsoleCommand extends Command<void> {
@override
Future<void> run() async {
final appId = argResults!.requiredOptionOrRest("app");
String? command = argResults!.option("command");

final spinner = context.printer.spin(start: false);

if (command case final command?) {
await _send(appId: appId, command: command, spinner: spinner);
if (argResults!.multiOptionOrRest("command", const ["app"])?.join(" ")
case final command?) {
await _send(appId, command, spinner);
return;
}

context.printer("Enter 'exit' to stop.");

while (true) {
context.printer.write("?> ".dim());
await Future.doWhile(() {
context.printer.write(_commandPrefix);

command = stdin.readLineSync();
if (command == null || command == "exit") break;
if (command.isEmpty) continue;
if (stdin.readLineSync() case final command?
when command.isNotEmpty && command != _exitCommand) {
return _send(appId, command, spinner);
}

if (!await _send(appId: appId, command: command, spinner: spinner)) break;
}
return false;
});
}

Future<bool> _send({
required String appId,
required String command,
required ISpin spinner,
}) async {
Future<bool> _send(String appId, String command, ISpin spinner) async {
spinner.start("Sending command...");

try {
Expand All @@ -62,23 +61,22 @@ final class AppConsoleCommand extends Command<void> {
body: {"command": command},
);

if (response["status"] == "ok") {
if (response["apps"]?["shell"] case final Map shell) {
spinner.stop();

if (response["apps"]?["shell"] case final Map shell) {
if (shell["stdout"] case final String content
when content.isNotEmpty) {
stdout.writeln(content);
}
if (shell["stdout"] case final String content when content.isNotEmpty) {
stdout.writeln(content);
}

if (shell["stderr"] case final String content
when content.isNotEmpty) {
stderr.writeln(content);
}
if (shell["stderr"] case final String content when content.isNotEmpty) {
stderr.writeln(content);
}
} else {
spinner.fail(resolveResponseMessage(response));

return true;
}

spinner.fail(resolveResponseMessage(response));

return true;
} on DiscloudApiException catch (e, s) {
final text = switch (e.code) {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/app/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class AppInfoCommand extends Command<void> {

@override
Future<void> run() async {
final appId = argResults?.optionOrRest("app") ?? "all";
final appId = argResults!.optionOrRest("app") ?? "all";

final spinner = context.printer.spin(text: "Fetching app info...");

Expand Down
10 changes: 5 additions & 5 deletions lib/commands/app/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ final class AppProfileCommand extends Command<void> {
AppProfileCommand() {
argParser
..addOption("app")
..addOption("name")
..addOption("avatar");
..addOption("name", abbr: "n")
..addOption("avatar", abbr: "a");
}

@override
Expand All @@ -22,14 +22,14 @@ final class AppProfileCommand extends Command<void> {
@override
Future<void> run() async {
final appId = argResults!.requiredOptionOrRest("app");
final name = argResults?.option("name");
final avatar = argResults?.option("avatar");
final name = argResults!.option("name");
final avatar = argResults!.option("avatar");

final spinner = context.printer.spin(text: "Changing app profile...");

final response = await context.api.put(
"/app/$appId/profile",
body: {"name": name, "avatarURL": avatar},
body: {"name": ?name, "avatarURL": ?avatar},
);

spinner.success(resolveResponseMessage(response));
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/app/ram.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class AppRamCommand extends Command<void> {
Future<void> run() async {
final appId = argResults!.requiredOptionOrRest("app");
final ramMB = max(
argResults!.requiredIntOptionOrRest("amount", const ["app"]),
argResults!.requiredIntOptionOrRest("amount", after: const ["app"]),
DiscloudRamMinByType.lowest.value,
);

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/snapshot/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class SnapshotDownloadCommand extends Command<void> with Disposable {
String appId, {
required ISpin spinner,
}) async {
if (argResults?.optionOrRest("version", const ["app"])
if (argResults!.optionOrRest("version", const ["app"])
case final String version) {
return version;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ final class SnapshotDownloadCommand extends Command<void> with Disposable {

Future<void> _download({required ISpin spinner, required Uri uri}) async {
final filename = uri.pathSegments.last;
final filepath = joinAll([?argResults?.option("dir"), filename]);
final filepath = joinAll([?argResults!.option("dir"), filename]);
final file = _file = .new(filepath);

final monitor = _monitor = .new();
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/snapshot/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class SnapshotInfoCommand extends Command<void> {

@override
Future<void> run() {
return switch (argResults?.optionOrRest("app")) {
return switch (argResults!.optionOrRest("app")) {
final String appId => _runSingle(appId),
_ => _runMulti(),
};
Expand All @@ -64,9 +64,9 @@ final class SnapshotInfoCommand extends Command<void> {
final response = await context.api.get(
"/snapshot",
query: {
"page": ?argResults?.option("page"),
"limit": ?argResults?.option("limit"),
"summary": ?argResults?.flag("summary").toString(),
"page": ?argResults!.option("page"),
"limit": ?argResults!.option("limit"),
"summary": argResults!.flag("summary").toString(),
},
);

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/system/locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ final class SystemLocaleCommand extends Command<void> {
"Short locale: ${Intl.shortLocale(Platform.localeName)}",
], "\n");

context.printer.info(sb);
context.printer(sb);
}
}
2 changes: 1 addition & 1 deletion lib/commands/team/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class TeamBackupCommand extends Command<void> with Disposable {

Future<void> _handleMulti(List list, ISpin spinner) async {
final client = _client = .new();
final dir = argResults?.optionOrRest("dir") ?? ".";
final dir = argResults!.optionOrRest("dir") ?? ".";

for (final data in list) {
final String appId = data["id"];
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/team/commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ final class TeamCommitCommand extends Command<void> with Disposable {
Future<void> run() async {
final directory = context.workspaceFolder;

final optionAppId = argResults?.optionOrRest("app");
final optionAppId = argResults!.optionOrRest("app");
final appId = optionAppId ?? await _getDiscloudConfigAppId(directory);

if (appId == null) throw Exception("Missing app id");

final glob =
argResults?.multiOptionOrRest("glob", [
argResults!.multiOptionOrRest("glob", [
if (optionAppId != null) "app",
]) ??
const ["**"];
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/team/ram.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class TeamRamCommand extends Command<void> {
Future<void> run() async {
final appId = argResults!.requiredOptionOrRest("app");
final ramMB = max(
argResults!.requiredIntOptionOrRest("amount", const ["app"]),
argResults!.requiredIntOptionOrRest("amount", after: const ["app"]),
DiscloudRamMinByType.lowest.value,
);

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/wait.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class WaitCommand extends Command<void> with Disposable {

@override
Future<void> run() async {
if (argResults?.rest.firstOrNull case final seconds?) {
if (argResults!.rest.firstOrNull case final seconds?) {
if (int.tryParse(seconds) case final seconds? when seconds.isPositive) {
await Future.delayed(.new(seconds: seconds));
}
Expand All @@ -29,6 +29,6 @@ final class WaitCommand extends Command<void> with Disposable {
@override
FutureOr<void> dispose() {
// ignore: no_runtimetype_tostring
context.printer.info("$hashCode $runtimeType disposed");
context.printer("$hashCode $runtimeType disposed");
}
}
8 changes: 4 additions & 4 deletions lib/commands/zip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class ZipCommand extends Command<void> with Disposable {
final description = "Make zip";

int? get _compressionLevel {
if (argResults?.option("level") case final l?) return .parse(l);
if (argResults!.option("level") case final l?) return .parse(l);
return null;
}

Expand All @@ -42,11 +42,11 @@ final class ZipCommand extends Command<void> with Disposable {
Future<void> run() async {
final directory = context.workspaceFolder;

final encoding = argResults?.option("encoding");
final out = argResults?.option("out") ?? "${basename(directory.path)}.zip";
final encoding = argResults!.option("encoding");
final out = argResults!.option("out") ?? "${basename(directory.path)}.zip";
final glob = argResults!.multiOptionOrRest("glob") ?? const ["**"];
final level = _compressionLevel;
final password = argResults?.option("password");
final password = argResults!.option("password");

final spinner = context.printer.spin(text: "Zipping...");

Expand Down
Loading