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
4 changes: 2 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ Set your locale

Usage: discloud user locale [arguments]
-h, --help Print this usage information.
-l, --locale=<en-US>
-s, --system Use current system language (en-US)
-l, --locale=<en_US>
-s, --system Use current system language (en_US)
```

### zip
Expand Down
4 changes: 3 additions & 1 deletion lib/cli/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import "package:discloud/cli/spin/cli_spin.dart";
import "package:discloud/extensions/duration.dart";
import "package:discloud/extensions/list.dart";
import "package:discloud/services/discloud/api_client.dart";
import "package:intl/intl.dart";
import "package:local_store/local_store.dart";
import "package:path/path.dart";
import "package:tint/tint.dart";

part "locale.dart";
part "paths.dart";

class CliContext implements Disposable {
Expand Down Expand Up @@ -64,7 +66,7 @@ class CliContext implements Disposable {
final LocalStore store;
final IPrinter<CLISpin> printer;

String get locale => Platform.localeName;
String get locale => localeName;

Directory get workspaceFolder => _workspaceFolder;

Expand Down
8 changes: 8 additions & 0 deletions lib/cli/locale.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
part of "context.dart";

const String _localePattern = r"^\w{2}[-_]\w{2}$";
final RegExp _localeRegexp = .new(_localePattern);

final String localeName =
_localeRegexp.firstMatch(Platform.localeName)?.input ??
Intl.getCurrentLocale();
8 changes: 4 additions & 4 deletions lib/cli/paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ part of "context.dart";

final Directory _workspaceFolder = .current;

final _rootFilePath = Platform.resolvedExecutable;
final String _rootFilePath = Platform.resolvedExecutable;

final _rootPath = dirname(_rootFilePath);
final String _rootPath = dirname(_rootFilePath);

final String _userHomePath =
Platform.environment[const ["HOME", "USERPROFILE"].firstWhere(
Expand All @@ -14,6 +14,6 @@ final String _userHomePath =
},
)]!;

final _cliConfigDir = joinAll([_userHomePath, ".discloud"]);
final String _cliConfigDir = joinAll([_userHomePath, ".discloud"]);

final _cliConfigFilePath = joinAll([_cliConfigDir, ".cli"]);
final String _cliConfigFilePath = joinAll([_cliConfigDir, ".cli"]);
18 changes: 7 additions & 11 deletions lib/commands/user/locale.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import "dart:io";

import "package:args/command_runner.dart";
import "package:discloud/cli/context.dart";
import "package:discloud/extensions/command.dart";
import "package:discloud/utils/messages.dart";

final class UserLocaleCommand extends Command<void> {
static const _localePattern = r"^\w{2}[-_]\w{2}$";
static final _localeRegexp = RegExp(_localePattern);
static final _localeName =
_localeRegexp.firstMatch(Platform.localeName)?.input ?? "en-US";

UserLocaleCommand() {
argParser
..addOption("locale", abbr: "l", valueHelp: _localeName)
..addOption("locale", abbr: "l", valueHelp: localeName)
..addFlag(
"system",
abbr: "s",
help: "Use current system language ($_localeName)",
help: "Use current system language ($localeName)",
negatable: false,
);
}
Expand All @@ -31,9 +25,11 @@ final class UserLocaleCommand extends Command<void> {
Future<void> run() async {
final system = argResults!.flag("system");

final locale = system ? Platform.localeName : argResults!.option("locale");
final locale = system ? context.locale : argResults!.option("locale");

final spinner = context.printer.spin(text: "Defining locale...");
final spinner = context.printer.spin(
text: "Defining the user's locale to $locale...",
);

final response = await context.api.put("/locale/$locale");

Expand Down