CLI for Oblique Strategies.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

  1. import yargs from 'yargs';
  2. import { hideBin } from 'yargs/helpers';
  3. import {
  4. main,
  5. MainArgs,
  6. Presentation,
  7. PRESENTATION,
  8. } from './app';
  9. void main(
  10. yargs
  11. .option('cards', {
  12. alias: 'c',
  13. description: "List of source for generating cards. Can have 'default', a pipe-delimited string starting with 'text:' or a URL starting with file:/// or http[s]://",
  14. coerce: (c?: unknown) => {
  15. if (typeof c !== 'string') {
  16. return ['default'];
  17. }
  18. const theCards = c.split(';');
  19. if (theCards.length < 1) {
  20. return ['default'];
  21. }
  22. // dedupe so we don't have to generate some cards more likely than others
  23. return theCards.filter((card, i, cards) => cards.indexOf(card) === i);
  24. },
  25. default: 'default',
  26. })
  27. .option('formatted', {
  28. alias: 'f',
  29. description: 'Flag when the output should be formatted.',
  30. coerce: (c?: unknown) => Boolean(c),
  31. default: false,
  32. })
  33. .option('presentation', {
  34. alias: 'p',
  35. description: 'Selection of how the card should be presented.',
  36. choices: PRESENTATION,
  37. coerce: (c?: unknown): Presentation => {
  38. if (typeof c !== 'string') {
  39. return 'plain';
  40. }
  41. const maybePresentation = c as Presentation;
  42. if (!PRESENTATION.includes(maybePresentation)) {
  43. return 'plain';
  44. }
  45. return maybePresentation;
  46. },
  47. default: 'plain',
  48. })
  49. .help()
  50. .parse(hideBin(process.argv)) as MainArgs,
  51. );