resolveDataDir function

String? resolveDataDir(
  1. ArgResults args, {
  2. bool systemScope = false,
})

The data root: the directory holding everything this installation keeps — credentials and identity, plus (for a Hub) the fleet data underneath it.

Resolves --data-dir when given, else the machine-wide root under systemScope, else OmnyServerHome.resolve (~/.omnyserver). Returns null only for --ephemeral, which asks for no persistence at all.

Always resolving is deliberate: a Hub with no data directory silently forgets the fleet, the audit trail and every credential grant add issued — on every restart. Opting into that should be explicit, hence --ephemeral.

Implementation

String? resolveDataDir(ArgResults args, {bool systemScope = false}) {
  final raw = (args['data-dir'] as String?)?.trim();
  final explicit = raw != null && raw.isNotEmpty;
  final ephemeral = args['ephemeral'] as bool;

  if (ephemeral) {
    if (explicit) {
      throw CliError(
        'use either --data-dir or --ephemeral, not both '
        '(--ephemeral means "persist nothing")',
      );
    }
    return null;
  }
  if (explicit) return p.normalize(p.absolute(raw));
  return systemScope ? systemDataDir() : OmnyServerHome.resolve();
}