How to use the @boost/common.optimal function in @boost/common

To help you get started, we’ve selected a few @boost/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github milesj / boost / packages / cli / src / decorators / Usage.ts View on Github external
return (target: Object) => {
    const meta = optimal(
      {
        ...config,
        description,
        path,
      },
      commandBlueprint,
      {
        name: path,
        unknown: false,
      },
    );

    Reflect.defineMetadata(META_PATH, meta.path, target);
    Reflect.defineMetadata(META_CONFIG, meta, target);

    // Also update static properties on constructor
github milesj / boost / packages / cli / src / metadata / registerOption.ts View on Github external
throw new TypeError(`Cannot define option as class property "${property}" does not exist.`);
  }

  const options: CommandMetadata['options'] = Reflect.getMetadata(META_OPTIONS, target) ?? {};
  const name = String(property);
  let blueprint: Blueprint;

  if (config.type === 'boolean') {
    blueprint = flagBlueprint;
  } else if (config.type === 'number') {
    blueprint = config.multiple ? numbersOptionBlueprint : numberOptionBlueprint;
  } else {
    blueprint = config.multiple ? stringsOptionBlueprint : stringOptionBlueprint;
  }

  options[name] = optimal(config, blueprint as Blueprint, {
    name: `Option "${name}"`,
    unknown: false,
  });

  Reflect.defineMetadata(META_OPTIONS, options, target);
}