edf2csv 0.7.252 → 0.7.254

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -97,6 +97,13 @@ Examples
97
97
  edf2csv /data/*.edf --out ./converted --jobs auto
98
98
  edf2csv /data/study --out ./converted --jobs auto
99
99
  `;
100
+ /**
101
+ * The placeholder `--help` writes after each option that takes a value, read off `--help`.
102
+ *
103
+ * Read rather than listed again so the two cannot part company: `--channels <list>` is what
104
+ * the usage block says and what the reference documents, and the refusals below quote it back.
105
+ */
106
+ const VALUE_NAMES = new Map([...USAGE.matchAll(/--([a-z-]+) (<[a-z]+>)/gu)].map((m) => [m[1], m[2]]));
100
107
  /**
101
108
  * A continuation line under an `error: ` or `interrupted (SIGINT): ` head.
102
109
  *
@@ -1983,6 +1990,17 @@ function survivesBare(text) {
1983
1990
  function singleQuoted(text) {
1984
1991
  return `'${text.replaceAll("'", "'\\''")}'`;
1985
1992
  }
1993
+ /**
1994
+ * Which spelling of an option the command actually used.
1995
+ *
1996
+ * Node names both — `-c, --channels` — and the reader typed one of them. Quoting the pair back
1997
+ * makes a refusal about a command nobody wrote.
1998
+ */
1999
+ function asTyped(short, long, argv) {
2000
+ if (short === undefined)
2001
+ return long;
2002
+ return argv.some((a) => a === long || a.startsWith(`${long}=`)) ? long : short;
2003
+ }
1986
2004
  /**
1987
2005
  * A `parseArgs` failure, in this tool's words where they are better than Node's.
1988
2006
  *
@@ -2030,6 +2048,37 @@ function usageMessage(error, argv) {
2030
2048
  if (code !== 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE') {
2031
2049
  return asError(raw);
2032
2050
  }
2051
+ /*
2052
+ Node's voice, in the two refusals this file had not taken over.
2053
+
2054
+ `unknownOption` and the ambiguous-value branch below both rewrite their message into this
2055
+ tool's words. Forgetting a value did not, so the commonest slip of the three came back as
2056
+
2057
+ error: Option '-c, --channels <value>' argument missing
2058
+
2059
+ which names both spellings when the reader typed one, ends without the full stop 68 of
2060
+ this tool's 69 diagnostics carry, and quotes a placeholder — `<value>` — that appears
2061
+ nowhere in `--help`, the reference, or any other message here: this option takes a
2062
+ `<list>`, `--start` takes a `<time>`, `--out` a `<dir>`. Nothing in it tells the reader
2063
+ what to write, and it is the one refusal where that is the whole question.
2064
+
2065
+ `--gzip=yes` is the same failure from the other side, and had the same treatment.
2066
+ */
2067
+ const missing = /^Option '(?:(-[A-Za-z]), )?(--[a-z-]+) <value>' argument missing$/u.exec(raw);
2068
+ if (missing) {
2069
+ const long = missing[2];
2070
+ return printableLines(`error: ${asTyped(missing[1], long, argv)} needs a value and was given none.\n` +
2071
+ ` It takes one: ${long} ${VALUE_NAMES.get(long.slice(2)) ?? '<value>'}.`);
2072
+ }
2073
+ const unwanted = /^Option '(?:(-[A-Za-z]), )?(--[a-z-]+)' does not take an argument$/u.exec(raw);
2074
+ if (unwanted) {
2075
+ const long = unwanted[2];
2076
+ const typed = asTyped(unwanted[1], long, argv);
2077
+ const given = argv.find((a) => a.startsWith(`${long}=`))?.slice(long.length + 1);
2078
+ return printableLines(`error: ${typed} is a switch and takes no value` +
2079
+ `${given === undefined ? '' : `, but was given "${given}"`}.\n` +
2080
+ ` Write it on its own: ${typed}`);
2081
+ }
2033
2082
  const ambiguous = /^Option '(-[^']+)' argument is ambiguous/u.exec(raw);
2034
2083
  if (!ambiguous)
2035
2084
  return asError(raw);