values.js 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. import {getFdSpecificValue} from '../arguments/specific.js';
  2. // The `verbose` option can have different values for `stdout`/`stderr`
  3. export const isVerbose = ({verbose}, fdNumber) => getFdVerbose(verbose, fdNumber) !== 'none';
  4. // Whether IPC and output and logged
  5. export const isFullVerbose = ({verbose}, fdNumber) => !['none', 'short'].includes(getFdVerbose(verbose, fdNumber));
  6. // The `verbose` option can be a function to customize logging
  7. export const getVerboseFunction = ({verbose}, fdNumber) => {
  8. const fdVerbose = getFdVerbose(verbose, fdNumber);
  9. return isVerboseFunction(fdVerbose) ? fdVerbose : undefined;
  10. };
  11. // When using `verbose: {stdout, stderr, fd3, ipc}`:
  12. // - `verbose.stdout|stderr|fd3` is used for 'output'
  13. // - `verbose.ipc` is only used for 'ipc'
  14. // - highest `verbose.*` value is used for 'command', 'error' and 'duration'
  15. const getFdVerbose = (verbose, fdNumber) => fdNumber === undefined
  16. ? getFdGenericVerbose(verbose)
  17. : getFdSpecificValue(verbose, fdNumber);
  18. // When using `verbose: {stdout, stderr, fd3, ipc}` and logging is not specific to a file descriptor.
  19. // We then use the highest `verbose.*` value, using the following order:
  20. // - function > 'full' > 'short' > 'none'
  21. // - if several functions are defined: stdout > stderr > fd3 > ipc
  22. const getFdGenericVerbose = verbose => verbose.find(fdVerbose => isVerboseFunction(fdVerbose))
  23. ?? VERBOSE_VALUES.findLast(fdVerbose => verbose.includes(fdVerbose));
  24. // Whether the `verbose` option is customized using a function
  25. export const isVerboseFunction = fdVerbose => typeof fdVerbose === 'function';
  26. export const VERBOSE_VALUES = ['none', 'short', 'full'];