< Summary - Envilder CLI

Information
Class: src/envilder/core/application/dispatch/DispatchActionCommand.ts
Assembly: Default
File(s): src/envilder/core/application/dispatch/DispatchActionCommand.ts
Tag: 561_41292037308
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 76
Line coverage: 100%
Branch coverage
100%
Covered branches: 9
Total branches: 9
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/core/application/dispatch/DispatchActionCommand.ts

#LineLine coverage
 1import type { CliOptions } from '../../domain/CliOptions.js';
 2import type { MapFileTarget } from '../../domain/MapFileUpdate.js';
 3import { OperationMode } from '../../domain/OperationMode.js';
 4
 5export class DispatchActionCommand {
 6  constructor(
 987    public readonly map?: string,
 988    public readonly envfile?: string,
 989    public readonly key?: string,
 9810    public readonly value?: string,
 9811    public readonly secretPath?: string,
 9812    public readonly profile?: string,
 9813    public readonly mode: OperationMode = OperationMode.PULL_SECRETS_TO_ENV,
 14    /** Exec mode: the program to run. */
 9815    public readonly command?: string,
 16    /** Exec mode: arguments passed to the program verbatim. */
 9817    public readonly args: readonly string[] = [],
 18    /** Exec mode: where secrets come from, shown in the summary line. */
 9819    public readonly sourceLabel?: string,
 20    /** Single-secret push: where the secret goes, for the map file update. */
 9821    public readonly mapTarget?: MapFileTarget,
 22  ) {}
 23
 24  /**
 25   * Builds the command for `envilder exec`: run `command` with the secrets of
 26   * the map file in its environment.
 27   */
 28  static forExec(
 29    map: string,
 30    command: string,
 31    args: readonly string[],
 32    sourceLabel?: string,
 33  ): DispatchActionCommand {
 3934    return new DispatchActionCommand(
 35      map,
 36      undefined,
 37      undefined,
 38      undefined,
 39      undefined,
 40      undefined,
 41      OperationMode.EXEC,
 42      command,
 43      [...args],
 44      sourceLabel,
 45    );
 46  }
 47
 48  static fromCliOptions(options: CliOptions): DispatchActionCommand {
 4049    const mode = DispatchActionCommand.determineOperationMode(options);
 4050    return new DispatchActionCommand(
 51      options.map,
 52      options.envfile,
 53      options.key,
 54      options.value,
 55      options.secretPath,
 56      options.profile,
 57      mode,
 58      undefined,
 59      [],
 60      undefined,
 61      options.mapTarget,
 62    );
 63  }
 64
 65  static determineOperationMode(options: CliOptions): OperationMode {
 6566    if (options.key && options.value && options.secretPath) {
 3267      return OperationMode.PUSH_SINGLE;
 68    }
 69
 3370    if (options.push) {
 471      return OperationMode.PUSH_ENV_TO_SECRETS;
 72    }
 73
 2974    return OperationMode.PULL_SECRETS_TO_ENV;
 75  }
 76}