@pixlcore/xycli 1.0.4 → 1.0.5
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/index.js +4 -1
- package/package.json +1 -1
- package/test/help.test.js +7 -0
- package/test/helpers/crlf-help.js +18 -0
package/index.js
CHANGED
|
@@ -380,7 +380,10 @@ const app = {
|
|
|
380
380
|
printHelp(heading) {
|
|
381
381
|
// print named section from help file
|
|
382
382
|
heading = heading.toLowerCase();
|
|
383
|
-
|
|
383
|
+
// Git may check this file out with CRLF on Windows. Normalize it before
|
|
384
|
+
// matching headings so the parser behaves identically on every platform.
|
|
385
|
+
var md = fs.readFileSync(Path.join(__dirname, 'docs', 'help.md'), 'utf8')
|
|
386
|
+
.replace(/\r\n?/g, '\n').trim() + "\n\n# end sentinel\n";
|
|
384
387
|
var re = new RegExp( "(^|\\n)(\\#+)\\s+(" + Tools.escapeRegExp(heading) + ")\\n([\\s\\S]*?)\\n\#+\\s+" );
|
|
385
388
|
var matches = md.match(re);
|
|
386
389
|
if (!matches) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixlcore/xycli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A complete command-line interface for the xyOps workflow automation system.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@pixlcore.com>",
|
|
6
6
|
"homepage": "https://github.com/pixlcore/xycli",
|
package/test/help.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { test } = require('node:test');
|
|
2
2
|
const assert = require('node:assert/strict');
|
|
3
|
+
const Path = require('node:path');
|
|
3
4
|
const { xy } = require('./helpers/common.js');
|
|
4
5
|
|
|
5
6
|
// Deliberately shadow any developer-machine configuration. Help and command
|
|
@@ -10,12 +11,18 @@ const offlineEnv = {
|
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
const offlineFailure = { fail: true, env: offlineEnv };
|
|
14
|
+
const crlfHelpPreload = Path.join(__dirname, 'helpers', 'crlf-help.js');
|
|
13
15
|
|
|
14
16
|
test('help is available without server credentials', () => {
|
|
15
17
|
const output = xy(['help'], { env: offlineEnv });
|
|
16
18
|
assert.match(output, /HELP: OVERVIEW/);
|
|
17
19
|
});
|
|
18
20
|
|
|
21
|
+
test('help parses a document with Windows line endings', () => {
|
|
22
|
+
const output = xy(['help'], { env: offlineEnv, preload: crlfHelpPreload });
|
|
23
|
+
assert.match(output, /HELP: OVERVIEW/);
|
|
24
|
+
});
|
|
25
|
+
|
|
19
26
|
test('help suggests the closest chapter for a typo', () => {
|
|
20
27
|
const output = xy(['help', 'event', 'udpate'], offlineFailure);
|
|
21
28
|
assert.match(output, /Could not find help chapter for "event udpate"\. Did you mean "event update"\?/);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Force the help document through the same CRLF checkout transformation Git
|
|
2
|
+
// commonly applies on Windows, so this regression is covered on every runner.
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const Path = require('node:path');
|
|
5
|
+
const readFileSync = fs.readFileSync;
|
|
6
|
+
|
|
7
|
+
fs.readFileSync = function(file) {
|
|
8
|
+
var contents = readFileSync.apply(this, arguments);
|
|
9
|
+
var filename = String(file);
|
|
10
|
+
var is_help = (Path.basename(filename) == 'help.md') &&
|
|
11
|
+
(Path.basename(Path.dirname(filename)) == 'docs');
|
|
12
|
+
|
|
13
|
+
if (is_help && (typeof(contents) == 'string')) {
|
|
14
|
+
return contents.replace(/\r?\n/g, '\r\n');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return contents;
|
|
18
|
+
};
|