main function
Implementation
void main(List<String> args) async {
final command = args.first;
final selected = commands.firstWhere(
(e) => e.args == command,
orElse: () => commands.first,
);
if (selected == commands.first) {
print("Available commands:\n".green().bold());
for (var command in commands) {
print("${command.args} - ${command.description.blue()}\n");
}
return;
}
final configFile = File(
path.join(
getRootDirectory(),
"localesync.config.json",
),
);
if (!await configFile.exists()) {
print(
"localesync.config.json not found. Please refer to https://docs.localesync.com/config#config-file to fix this"
.red(),
);
return;
}
final config =
jsonDecode(await configFile.readAsString()) as Map<String, dynamic>;
if (!config.containsKey("repository_id")) {
print(
"missing repository_id in localesync.config.json. Please refer to https://docs.localesync.com/config#config-file to fix this"
.red(),
);
return;
} else if (!config.containsKey("api_token")) {
print(
"missing api_token in localesync.config.json. Please refer to https://docs.localesync.com/config#config-file to fix this"
.red(),
);
return;
}
if (selected.args == sync) {
await _handleCommand(
selected: commands[2],
config: config,
);
await _handleCommand(
selected: commands[1],
config: config,
);
await _handleCommand(
selected: commands[3],
config: config,
);
return;
}
_handleCommand(
selected: selected,
config: config,
);
}