serviceStartArgs function

  1. @visibleForTesting
List<String> serviceStartArgs(
  1. String role,
  2. ArgResults args
)

Reconstructs the omnyserver <role> start … argument vector from args, absolutizing filesystem paths so the baked-in command works from any directory.

Implementation

@visibleForTesting
List<String> serviceStartArgs(String role, ArgResults args) {
  final systemScope = args['system'] as bool;
  final out = <String>[role, 'start'];
  if (role == 'hub') {
    emitOption(out, 'host', args['host']);
    emitOption(out, 'port', args['port']);
    emitPathOption(out, 'cert', args['cert']);
    emitPathOption(out, 'key', args['key']);
    emitPathOption(out, 'tls-dir', args['tls-dir']);
    // A URL mount point, not a filesystem path — never absolutize it.
    emitOption(out, 'node-path', args['node-path']);
    emitFlag(out, 'shell', args['shell'] as bool);
    emitOption(out, 'shell-path', args['shell-path']);
    emitOption(out, 'api-token', args['api-token']);
    emitMultiOption(out, 'grant', args['grant'] as List<String>);
    emitMultiOption(out, 'alert', args['alert'] as List<String>);
    emitMultiOption(out, 'cors-origin', args['cors-origin'] as List<String>);
    emitPathOption(out, 'ai-config', args['ai-config']);
    final root = resolveDataDir(args, systemScope: systemScope);
    if (root == null) {
      emitFlag(out, 'ephemeral', true);
    } else {
      emitOption(out, 'data-dir', hubDataDir(root));
    }
  } else {
    emitOption(out, 'hub', args['hub']);
    emitOption(out, 'id', args['id']);
    emitOption(out, 'principal', args['principal']);
    emitOption(out, 'token', args['token']);
    emitPathOption(out, 'ca', args['ca']);
    emitFlag(out, 'insecure', args['insecure'] as bool);
    emitFlag(out, 'with-shell', args['with-shell'] as bool);
    emitOption(out, 'shell-path', args['shell-path']);
    emitNegatableFlag(out, 'ship-logs', args['ship-logs'] as bool);
    emitMultiOption(out, 'label', args['label'] as List<String>);
    emitMultiOption(out, 'shell-label', args['shell-label'] as List<String>);
    // `node start` has no --data-dir; the node's state rides in
    // OMNYSERVER_HOME, set in the descriptor's environment.
  }
  return out;
}