All files / src/Program/options ogmios.ts

91.66% Statements 11/12
100% Branches 2/2
66.66% Functions 2/3
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36  43x 43x 43x   43x 43x 43x     43x 43x 43x               43x                              
import { Command } from 'commander';
import { Ogmios } from '@cardano-sdk/ogmios';
import { addOptions, newOption } from './util';
import { urlValidator } from '../../util/validators';
 
const OGMIOS_URL_DEFAULT = (() => {
  const connection = Ogmios.createConnectionObject();
  return connection.address.webSocket;
})();
 
export enum OgmiosOptionDescriptions {
  SrvServiceName = 'Ogmios SRV service name',
  Url = 'Ogmios URL'
}
 
export interface OgmiosProgramOptions {
  ogmiosUrl?: URL;
  ogmiosSrvServiceName?: string;
}
 
export const withOgmiosOptions = (command: Command) =>
  addOptions(command, [
    newOption(
      '--ogmios-srv-service-name <ogmiosSrvServiceName>',
      OgmiosOptionDescriptions.SrvServiceName,
      'OGMIOS_SRV_SERVICE_NAME'
    ),
    newOption(
      '--ogmios-url <ogmiosUrl>',
      OgmiosOptionDescriptions.Url,
      'OGMIOS_URL',
      urlValidator(OgmiosOptionDescriptions.Url),
      new URL(OGMIOS_URL_DEFAULT)
    ).conflicts('ogmiosSrvServiceName')
  ]);