run method
run the command. args are the words after the name.
Implementation
@override
Future<void> run(List<String> args) async {
String? store = _store(args);
if (store == null) {
print(
'Unknown option. Use --store=file, --store=redis, --store=memory '
'or --store=database (file when not given).',
);
exitCode = 1;
return;
}
Installer installer = Installer(root: root, runner: runner);
String app = installer.appName;
/// first, so an app without the AppEnv class gets the hint and
/// nothing else is changed
for (String getter in envGetters(store)) {
installer.addEnvGetter(getter);
}
if (!installer.ok) {
installer.printSummary(<String>[
'lib/config/env.dart has no `abstract class AppEnv`. Run '
'`dox env:generate` to make it, then run this again.',
]);
return;
}
await installer.addDependency('dox_cache');
if (store == 'database') {
await installer.addDependency('dox_cache_database');
}
bool madeConfig = installer.writeFile(
'lib/config/cache.dart',
cacheConfig(app, store),
);
if (store == 'database') {
installer.writeFile('lib/providers/cache_provider.dart', cacheProvider);
}
bool wired = _addToAppConfig(installer, app, madeConfig);
Map<String, String> keys = envKeys(store);
for (String key in keys.keys) {
installer.addEnv(key, keys[key]!);
}
bool hasOrm =
installer.hasDependency('dox_orm') &&
installer.hasDependency('dox_migration');
if (store == 'database' && hasOrm) _addMigration(installer);
await installer.buildRunner();
String config = File('${installer.root.path}/lib/config/cache.dart')
.readAsStringSync();
installer.printSummary(<String>[
if (!wired)
'Add this line to the AppConfig(...) call in lib/config/app.dart '
'(use the name of your CacheConfig variable): `cache: cache,` '
"and `import 'package:$app/config/cache.dart';`.",
if (!config.contains("'$store'"))
"lib/config/cache.dart has no '$store' store. Add one, see the "
'cache docs.',
if (store != 'file')
'Check CACHE_STORE=$store in .env. A key that was already there is '
'not changed.',
if (store == 'database' && !hasOrm)
'The database store needs the ORM. Run `dox add orm` first, then '
'`dox cache:table`.',
if (store == 'database' && hasOrm) 'Make the cache table: `dox migrate`.',
]);
}