run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<void> run() async {
di<ValueMapper>().init(
bytesPrefix: getArgBytesPrefix(argResults),
locationPrefix: getArgLocationPrefix(argResults),
referencePrefix: getArgReferencePrefix(argResults),
datetimePrefix: getArgDateTimePrefix(argResults),
);
di<DocumentMapper>().init(metaPrefix: getArgMetaPrefix(argResults));
final firestore = await initFirestore(
project: getArgProject(argResults),
database: getArgDatabase(argResults),
usage: usage,
);
final restArgs = argResults!.rest;
if (restArgs.isEmpty) {
throw UsageException('Command must have an argument', usage);
} else if (restArgs.length > 1) {
throw UsageException('Command must have only one argument', usage);
}
final relPath = restArgs.single;
final jsonIn = await readFromIn(fileName: getArgIn(argResults));
final jsonObject = jsonDecode(jsonIn);
if (jsonObject is! JsonObject) {
throw UsageException(
'''
Input JSON must have an Object format.
More about the Object format here: https://datatracker.ietf.org/doc/html/rfc8259#section-4
''',
usage,
);
}
await firestore.addCollection(
documentPath: relPath,
json: jsonObject,
changeRootName: getArgChangeRootName(argResults),
);
}