@gkalpak/aliases 0.9.4 → 0.10.1
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/README.md +4 -4
- package/bin/aio/__a-builds-dir.js +5 -7
- package/bin/aio/aioall.js +5 -5
- package/bin/aio/aioatt.js +5 -5
- package/bin/aio/aiobd.js +5 -5
- package/bin/aio/aiord.js +5 -5
- package/bin/aio/aiorm.js +5 -5
- package/bin/config/cfgbash.js +3 -4
- package/bin/config/cfgbash.wsl.js +3 -4
- package/bin/config/cfggit.js +3 -4
- package/bin/config/cfggit.wsl.js +4 -5
- package/bin/config/cfgvim.js +5 -3
- package/bin/docker/dkrall.js +5 -5
- package/bin/docker/dkratt.js +5 -5
- package/bin/docker/dkrbd.js +5 -5
- package/bin/docker/dkrrd.js +5 -5
- package/bin/docker/dkrrm.js +5 -5
- package/bin/git/__g-pick-branch.js +5 -7
- package/bin/git/__g-pick-commit.js +5 -7
- package/bin/git/gaa.js +5 -5
- package/bin/git/gb.js +5 -5
- package/bin/git/gbc.js +5 -5
- package/bin/git/gbcm.js +5 -5
- package/bin/git/gbd.js +5 -5
- package/bin/git/gcl.js +5 -5
- package/bin/git/gcm.js +5 -5
- package/bin/git/gcma.js +5 -5
- package/bin/git/gcmane.js +5 -5
- package/bin/git/gcmf.js +5 -5
- package/bin/git/gcmfc.js +5 -5
- package/bin/git/gcmfs.js +5 -5
- package/bin/git/gcmi.js +5 -5
- package/bin/git/gcmia.js +5 -5
- package/bin/git/gcmiane.js +5 -5
- package/bin/git/gcmif.js +5 -5
- package/bin/git/gcmifc.js +5 -5
- package/bin/git/gcmifs.js +5 -5
- package/bin/git/gco.js +5 -5
- package/bin/git/gcoghpr-cleanup.js +5 -5
- package/bin/git/gcoghpr.js +5 -7
- package/bin/git/gcom.js +5 -5
- package/bin/git/gcopr.js +5 -5
- package/bin/git/gcp.js +5 -5
- package/bin/git/gcpa.js +5 -5
- package/bin/git/gcpc.js +5 -5
- package/bin/git/gcpx.js +5 -5
- package/bin/git/gcpxl.js +5 -5
- package/bin/git/gd.js +5 -5
- package/bin/git/gd1.js +5 -5
- package/bin/git/gdefb.js +5 -5
- package/bin/git/gdh.js +5 -5
- package/bin/git/gdn.js +5 -5
- package/bin/git/gdn1.js +5 -5
- package/bin/git/gdnh.js +5 -5
- package/bin/git/gl.js +5 -5
- package/bin/git/gl1.js +5 -5
- package/bin/git/gl1g.js +5 -5
- package/bin/git/gmt.js +5 -5
- package/bin/git/gngprh.js +5 -5
- package/bin/git/gngprm.js +5 -5
- package/bin/git/gp.js +5 -5
- package/bin/git/gp1.js +5 -5
- package/bin/git/gpf.js +5 -5
- package/bin/git/gpr.js +5 -5
- package/bin/git/gpro.js +5 -5
- package/bin/git/gprom.js +5 -5
- package/bin/git/gpru.js +5 -5
- package/bin/git/gprum.js +5 -5
- package/bin/git/grb.js +5 -5
- package/bin/git/grba.js +5 -5
- package/bin/git/grbc.js +5 -5
- package/bin/git/grbi.js +5 -5
- package/bin/git/grbia.js +5 -5
- package/bin/git/grbin.js +5 -5
- package/bin/git/grbm.js +5 -5
- package/bin/git/grs.js +5 -5
- package/bin/git/grs1.js +5 -5
- package/bin/git/gs.js +5 -5
- package/bin/git/gsh.js +5 -5
- package/bin/git/gshn.js +5 -5
- package/bin/git/gst.js +5 -5
- package/bin/git/gstk.js +5 -5
- package/bin/git/gstl.js +5 -5
- package/bin/git/gstp.js +5 -5
- package/bin/git/gsync.js +5 -5
- package/bin/misc/alv.js +1 -2
- package/bin/misc/halp.js +2 -2
- package/bin/misc/ll.darwin.js +5 -5
- package/bin/misc/ll.js +5 -5
- package/bin/misc/lla.darwin.js +5 -5
- package/bin/misc/lla.js +5 -5
- package/bin/misc/osv.darwin.js +5 -5
- package/bin/misc/osv.js +5 -5
- package/bin/misc/osv.win32.js +5 -5
- package/bin/misc/salfup.js +5 -5
- package/bin/node/nad.js +5 -5
- package/bin/node/naga.js +5 -5
- package/bin/node/nap.js +5 -5
- package/bin/node/niin.js +5 -5
- package/bin/node/nls.js +5 -5
- package/bin/node/nls1.js +5 -5
- package/bin/node/nlsg.js +5 -5
- package/bin/node/nlsg1.js +5 -5
- package/bin/node/nr.js +5 -5
- package/bin/node/nrd.js +5 -5
- package/bin/node/nrin.js +5 -5
- package/bin/node/nrp.js +5 -5
- package/bin/node/nrx.js +5 -5
- package/bin/node/ns.js +5 -5
- package/bin/node/nsin.js +5 -5
- package/bin/node/nsx.js +5 -5
- package/bin/node/nt.js +5 -5
- package/bin/node/ntin.js +5 -5
- package/bin/node/ntx.js +5 -5
- package/bin/node/nua.js +5 -5
- package/bin/node/nud.js +5 -5
- package/bin/node/nup.js +5 -5
- package/bin/node/nv.js +5 -5
- package/bin/node/nvls.js +5 -5
- package/bin/node/nvls.win32.js +5 -5
- package/bin/node/nvlsa.js +5 -5
- package/bin/node/nvlsa.win32.js +5 -5
- package/bin/node/nvmup.js +5 -5
- package/bin/node/nvmup.win32.js +5 -5
- package/bin/node/nvu.js +5 -7
- package/bin/node/srv.js +5 -5
- package/bin/node/srvw.js +5 -5
- package/bin/node/yad.js +5 -5
- package/bin/node/yaga.js +5 -5
- package/bin/node/yap.js +5 -5
- package/bin/node/yiin.js +5 -5
- package/bin/node/yls.js +5 -5
- package/bin/node/yls1.js +5 -5
- package/bin/node/ylsg.js +5 -5
- package/bin/node/ylsg1.js +5 -5
- package/bin/node/yr.js +5 -5
- package/bin/node/yrd.js +5 -5
- package/bin/node/yrin.js +5 -5
- package/bin/node/yrp.js +5 -5
- package/bin/node/yrx.js +5 -5
- package/bin/node/ys.js +5 -5
- package/bin/node/ysin.js +5 -5
- package/bin/node/ysx.js +5 -5
- package/bin/node/yt.js +5 -5
- package/bin/node/ytin.js +5 -5
- package/bin/node/ytx.js +5 -5
- package/bin/node/yua.js +5 -5
- package/bin/node/yud.js +5 -5
- package/bin/node/yup.js +5 -5
- package/lib/alias-scripts/a-builds-dir.js +65 -45
- package/lib/alias-scripts/g-pick-branch.js +44 -25
- package/lib/alias-scripts/g-pick-commit.js +44 -25
- package/lib/alias-scripts/gcoghpr.js +182 -195
- package/lib/alias-scripts/nvu.js +57 -49
- package/lib/alias.js +4 -5
- package/lib/constants.js +68 -47
- package/lib/helper.js +96 -88
- package/lib/utils.js +113 -58
- package/package.json +8 -6
- package/scripts/build.js +11 -10
- package/scripts/platformize-bin.js +7 -7
- package/scripts/test-pkg.js +14 -12
package/lib/alias.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
2
|
// Imports
|
|
5
|
-
|
|
3
|
+
import {getPlatform} from './utils.js';
|
|
4
|
+
|
|
6
5
|
|
|
7
6
|
// Interfaces
|
|
8
7
|
/*
|
|
@@ -38,7 +37,7 @@ class Alias/* implements IAlias */ {
|
|
|
38
37
|
filter(platform => platform !== 'default');
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
getSpec(platform =
|
|
40
|
+
getSpec(platform = getPlatform())/* IAliasSpec */ {
|
|
42
41
|
return this._specPerPlatform[platform] || this._specPerPlatform.default;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
@@ -79,7 +78,7 @@ class AliasSpecDefault extends AliasSpec {
|
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
// Exports
|
|
82
|
-
|
|
81
|
+
export {
|
|
83
82
|
Alias,
|
|
84
83
|
AliasDefault,
|
|
85
84
|
AliasSpec,
|
package/lib/constants.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
// Imports
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import {join, resolve as pathResolve} from 'node:path';
|
|
3
|
+
import {fileURLToPath} from 'node:url';
|
|
4
|
+
|
|
5
|
+
import {Alias, AliasDefault, AliasSpec, AliasSpecDefault, AliasUnknown} from './alias.js';
|
|
6
|
+
import {loadJson, stripIndentation} from './utils.js';
|
|
7
|
+
|
|
9
8
|
|
|
10
9
|
// Constants
|
|
11
|
-
const
|
|
12
|
-
const ROOT_DIR =
|
|
13
|
-
const BIN_DIR =
|
|
10
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
11
|
+
const ROOT_DIR = pathResolve(__dirname, '..');
|
|
12
|
+
const BIN_DIR = join(ROOT_DIR, 'bin');
|
|
13
|
+
|
|
14
|
+
const __pkg = loadJson(join(ROOT_DIR, 'package.json'));
|
|
15
|
+
const VERSION_STAMP = `${__pkg.name} v${__pkg.version}`;
|
|
16
|
+
|
|
17
|
+
const PR_REMOTE_ALIAS_PREFIX = 'gcoghpr';
|
|
18
|
+
const PR_LOCAL_BRANCH_PREFIX = 'gcoghpr';
|
|
19
|
+
|
|
14
20
|
const SOURCE_NVM_CMD = '. $NVM_DIR/nvm.sh';
|
|
15
21
|
const GIT_GET_DEFAULT_BRANCH_CMD =
|
|
16
22
|
`${['master', 'main'].map(b => `(git show-ref --heads --quiet ${b} && echo ${b})`).join(' || ')} || ` +
|
|
@@ -42,14 +48,14 @@ const DESC_REPLACEMENTS = {
|
|
|
42
48
|
'::__g-pick-commit --gkcu-returnOutput=1': '(interactively pick a commit)',
|
|
43
49
|
};
|
|
44
50
|
|
|
45
|
-
const DEF_CODE = AliasSpecDefault.DEF_CODE = (cmd, cfg = {}) =>
|
|
51
|
+
const DEF_CODE = AliasSpecDefault.DEF_CODE = (cmd, cfg = {}) => stripIndentation(`
|
|
46
52
|
#!/usr/bin/env node
|
|
47
|
-
|
|
53
|
+
import {commandUtils} from '@gkalpak/cli-utils';
|
|
54
|
+
import {isMain, onError} from '../../lib/utils.js';
|
|
48
55
|
// eslint-disable-next-line max-len
|
|
49
|
-
const cmd =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const {onError} = require('../../lib/utils');
|
|
56
|
+
const cmd = '${cmd.replace(/'/g, '\\\'')}';
|
|
57
|
+
export default cmd;
|
|
58
|
+
if (isMain(import.meta.url)) {
|
|
53
59
|
const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
|
|
54
60
|
// eslint-disable-next-line quotes
|
|
55
61
|
commandUtils.run(cmd, args, Object.assign(${JSON.stringify(cfg)}, config)).catch(onError);
|
|
@@ -58,12 +64,11 @@ const DEF_CODE = AliasSpecDefault.DEF_CODE = (cmd, cfg = {}) => utils.stripInden
|
|
|
58
64
|
|
|
59
65
|
const CFGBASH_SPEC = isWsl => new AliasSpec(
|
|
60
66
|
/* eslint-disable max-len */
|
|
61
|
-
|
|
67
|
+
stripIndentation(`
|
|
62
68
|
#!/usr/bin/env node
|
|
63
|
-
|
|
64
|
-
const utils = require('../../lib/utils');
|
|
69
|
+
import {stripIndentation} from '../../lib/utils.js';
|
|
65
70
|
/* eslint-disable max-len */
|
|
66
|
-
console.log(
|
|
71
|
+
console.log(stripIndentation(\`
|
|
67
72
|
### [Generated by: ${VERSION_STAMP}]
|
|
68
73
|
### Copy the following into '~/.bashrc':
|
|
69
74
|
|
|
@@ -86,11 +91,10 @@ const CFGBASH_SPEC = isWsl => new AliasSpec(
|
|
|
86
91
|
'Show configuration instructions for `bash`.');
|
|
87
92
|
|
|
88
93
|
const CFGGIT_SPEC_WITH_CRED_HELPER = credHelper => new AliasSpec(
|
|
89
|
-
|
|
94
|
+
stripIndentation(`
|
|
90
95
|
#!/usr/bin/env node
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
console.log(utils.stripIndentation(\`
|
|
96
|
+
import {stripIndentation} from '../../lib/utils.js';
|
|
97
|
+
console.log(stripIndentation(\`
|
|
94
98
|
### [Generated by: ${VERSION_STAMP}]
|
|
95
99
|
### Run the following commands:
|
|
96
100
|
|
|
@@ -111,16 +115,14 @@ const CFGGIT_SPEC_WITH_CRED_HELPER = credHelper => new AliasSpec(
|
|
|
111
115
|
`),
|
|
112
116
|
'Show configuration instructions for `git`.');
|
|
113
117
|
|
|
114
|
-
const SCRIPT_BACKED_CODE = (scriptName, desc) =>
|
|
118
|
+
const SCRIPT_BACKED_CODE = (scriptName, desc) => stripIndentation(`
|
|
115
119
|
#!/usr/bin/env node
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
import {commandUtils} from '@gkalpak/cli-utils';
|
|
121
|
+
import {main} from '../../lib/alias-scripts/${scriptName}.js';
|
|
122
|
+
import {isMain, onError} from '../../lib/utils.js';
|
|
123
|
+
export default '${desc.replace(/'/g, '\\\'')}';
|
|
124
|
+
if (isMain(import.meta.url)) {
|
|
121
125
|
const {args, config} = commandUtils.preprocessArgs(process.argv.slice(2));
|
|
122
|
-
|
|
123
|
-
const {main} = require('../../lib/alias-scripts/${scriptName}');
|
|
124
126
|
main(args, config).catch(onError);
|
|
125
127
|
}
|
|
126
128
|
`);
|
|
@@ -302,7 +304,7 @@ const ALIASES = {
|
|
|
302
304
|
gcp: new AliasDefault('git cherry-pick $*'),
|
|
303
305
|
gcpc: new AliasDefault('git cherry-pick --continue'),
|
|
304
306
|
gcpa: new AliasDefault('git cherry-pick --abort'),
|
|
305
|
-
gcpx: new AliasDefault(
|
|
307
|
+
gcpx: new AliasDefault(stripIndentation(`
|
|
306
308
|
echo " Cherry-picking SHA: $1 " &&
|
|
307
309
|
echo "----------------------------------------------------------------" &&
|
|
308
310
|
echo " " &&
|
|
@@ -471,18 +473,20 @@ const ALIASES = {
|
|
|
471
473
|
cfggit: new Alias({
|
|
472
474
|
default: CFGGIT_SPEC_WITH_CRED_HELPER('manager'),
|
|
473
475
|
wsl: CFGGIT_SPEC_WITH_CRED_HELPER(
|
|
474
|
-
'/mnt/c/Program\\\\ Files/Git/mingw64/bin/git-credential-manager
|
|
476
|
+
'/mnt/c/Program\\\\ Files/Git/mingw64/bin/git-credential-manager.exe'),
|
|
475
477
|
}),
|
|
476
478
|
|
|
477
479
|
|
|
478
480
|
// VIM
|
|
479
481
|
cfgvim: new Alias(new AliasSpec(
|
|
480
|
-
|
|
482
|
+
stripIndentation(`
|
|
481
483
|
#!/usr/bin/env node
|
|
482
|
-
|
|
484
|
+
import {readFileSync} from 'node:fs';
|
|
485
|
+
import {fileURLToPath} from 'node:url';
|
|
486
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
483
487
|
console.log('""" [Generated by: ${VERSION_STAMP}]');
|
|
484
488
|
console.log('""" Copy the following into \\'~/.vimrc\\':\\n');
|
|
485
|
-
console.log(
|
|
489
|
+
console.log(readFileSync(\`\${__dirname}/../../lib/assets/vimrc.txt\`, 'utf8').trim() + '\\n');
|
|
486
490
|
`),
|
|
487
491
|
'Show configuration instructions for `vim`.')),
|
|
488
492
|
},
|
|
@@ -508,25 +512,24 @@ const ALIASES = {
|
|
|
508
512
|
|
|
509
513
|
|
|
510
514
|
// SELF-UPDATE
|
|
511
|
-
salfup: new AliasDefault(`npm install --global ${
|
|
515
|
+
salfup: new AliasDefault(`npm install --global ${__pkg.name} $*`),
|
|
512
516
|
|
|
513
517
|
// VERSION
|
|
514
518
|
alv: new Alias(new AliasSpec(
|
|
515
|
-
|
|
519
|
+
stripIndentation(`
|
|
516
520
|
#!/usr/bin/env node
|
|
517
|
-
'use strict';
|
|
518
521
|
console.log('${VERSION_STAMP}');
|
|
519
522
|
`),
|
|
520
|
-
`Display the installed version of ${
|
|
523
|
+
`Display the installed version of ${__pkg.name}.`)),
|
|
521
524
|
|
|
522
525
|
// HELP
|
|
523
526
|
halp: new Alias(new AliasSpec(
|
|
524
|
-
|
|
527
|
+
stripIndentation(`
|
|
525
528
|
#!/usr/bin/env node
|
|
526
|
-
|
|
527
|
-
|
|
529
|
+
import {help} from '../../lib/helper.js';
|
|
530
|
+
help(...process.argv.slice(2));
|
|
528
531
|
`),
|
|
529
|
-
|
|
532
|
+
stripIndentation(`
|
|
530
533
|
Display this message. Variations:
|
|
531
534
|
- Pass a category name to list aliases of the specified category only.
|
|
532
535
|
(Example: \`halp node\`)
|
|
@@ -537,13 +540,31 @@ const ALIASES = {
|
|
|
537
540
|
`))),
|
|
538
541
|
},
|
|
539
542
|
};
|
|
543
|
+
const internal = {
|
|
544
|
+
_getDescReplacements,
|
|
545
|
+
};
|
|
540
546
|
|
|
541
547
|
// Exports
|
|
542
|
-
|
|
548
|
+
export {
|
|
543
549
|
ALIASES,
|
|
544
550
|
BIN_DIR,
|
|
545
551
|
DEF_CODE,
|
|
546
|
-
|
|
552
|
+
PR_REMOTE_ALIAS_PREFIX,
|
|
553
|
+
PR_LOCAL_BRANCH_PREFIX,
|
|
547
554
|
ROOT_DIR,
|
|
548
555
|
VERSION_STAMP,
|
|
556
|
+
|
|
557
|
+
getDescReplacements,
|
|
558
|
+
|
|
559
|
+
// Exposed for testing purposes only.
|
|
560
|
+
internal as _testing,
|
|
549
561
|
};
|
|
562
|
+
|
|
563
|
+
// Helpers
|
|
564
|
+
function _getDescReplacements() {
|
|
565
|
+
return DESC_REPLACEMENTS;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function getDescReplacements() {
|
|
569
|
+
return internal._getDescReplacements();
|
|
570
|
+
}
|
package/lib/helper.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
// Imports
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
import {AliasUnknown} from './alias.js';
|
|
5
|
+
import {ALIASES, getDescReplacements, VERSION_STAMP} from './constants.js';
|
|
6
|
+
import {capitalize, hasOwnProperty, onError, padRight, wrapLine} from './utils.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// Constants
|
|
10
|
+
const internal = {
|
|
11
|
+
_helpForCategory,
|
|
12
|
+
};
|
|
8
13
|
|
|
9
14
|
// Exports
|
|
10
|
-
|
|
15
|
+
export {
|
|
11
16
|
/**
|
|
12
17
|
* @function help
|
|
13
18
|
*
|
|
@@ -32,67 +37,33 @@ const helper = module.exports = {
|
|
|
32
37
|
*
|
|
33
38
|
* @return {Promise<void>} - A promise that resolves once the message has been printed.
|
|
34
39
|
*/
|
|
35
|
-
help
|
|
40
|
+
help,
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
// Exposed for testing purposes only.
|
|
43
|
+
internal as _testing,
|
|
39
44
|
};
|
|
40
45
|
|
|
41
|
-
//
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
+
// Helpers
|
|
47
|
+
function _helpForCategory(category, joiner) {
|
|
48
|
+
const publicAliases = Object.keys(category.spec).filter(aliasName => !/^__/.test(aliasName));
|
|
49
|
+
const maxNameLen = Math.max(...publicAliases.map(a => a.length));
|
|
50
|
+
const indent1 = ' '.repeat(2);
|
|
51
|
+
const indent2 = ' '.repeat(indent1.length + maxNameLen + joiner.length);
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'',
|
|
62
|
-
' Available aliases',
|
|
63
|
-
'===================',
|
|
64
|
-
'',
|
|
65
|
-
].join('\n');
|
|
66
|
-
const mainSection = matchedCategories.
|
|
67
|
-
filter(category => Object.keys(category.spec).length).
|
|
68
|
-
map(category => helper._helpForCategory(category, joiner)).
|
|
69
|
-
join(`\n\n${chalk.gray(sep)}\n\n`) || chalk.yellowBright(' Nothing to see here :(');
|
|
70
|
-
const footer = showAliases ? '' : [
|
|
71
|
-
'',
|
|
72
|
-
chalk.magenta(sep),
|
|
73
|
-
'',
|
|
74
|
-
'All aliases also accept the following arguments:',
|
|
75
|
-
'--gkcu-debug: Produce verbose, debug-friendly output.',
|
|
76
|
-
'--gkcu-dryrun: Print the command instead of actually running it. (Still experimental.)',
|
|
77
|
-
'--gkcu-sapVersion: Choose a different implementation for the command runner. (Default: 2)',
|
|
78
|
-
'--gkcu-suppressTbj: Suppress the "Terminate batch job (Y/N)?" confirmation on Windows. (Still experimental.)',
|
|
79
|
-
' Does not work with certain types of commands (e.g. `vim`).',
|
|
80
|
-
'',
|
|
81
|
-
utils.wrapLine(
|
|
82
|
-
'(NOTE: All arguments starting with `--gkcu-` will be ignored when substituting input arguments or ' +
|
|
83
|
-
'determining their index.)'),
|
|
84
|
-
'',
|
|
85
|
-
].join('\n');
|
|
86
|
-
|
|
87
|
-
const message = [
|
|
88
|
-
chalk.magenta(header),
|
|
89
|
-
mainSection,
|
|
90
|
-
chalk.gray(footer),
|
|
91
|
-
].join('\n');
|
|
92
|
-
|
|
93
|
-
console.log(message);
|
|
94
|
-
}).
|
|
95
|
-
catch(utils.onError);
|
|
53
|
+
const headerStyle = category.problematic ? chalk.yellowBright : chalk.cyan;
|
|
54
|
+
const aliasStyle = category.problematic ? chalk.red : chalk.green;
|
|
55
|
+
|
|
56
|
+
const headerText = `${category.name} aliases${category.partial ? ' subset' : ''}:`;
|
|
57
|
+
|
|
58
|
+
return [
|
|
59
|
+
headerStyle(capitalize(headerText)),
|
|
60
|
+
'',
|
|
61
|
+
publicAliases.
|
|
62
|
+
map(aliasName => [aliasName, getDescription(category.spec[aliasName])]).
|
|
63
|
+
map(([aliasName, aliasDesc]) => [padRight(aliasName, maxNameLen), wrapMultiline(aliasDesc, indent2)]).
|
|
64
|
+
map(([aliasName, aliasDesc]) => `${indent1}${aliasStyle(aliasName)}${chalk.gray(joiner)}${aliasDesc}`).
|
|
65
|
+
join('\n'),
|
|
66
|
+
].join('\n');
|
|
96
67
|
}
|
|
97
68
|
|
|
98
69
|
function createCategoriesOnTheFly(aliasNames) {
|
|
@@ -117,11 +88,11 @@ function createCategoriesOnTheFly(aliasNames) {
|
|
|
117
88
|
const foundNames = [];
|
|
118
89
|
|
|
119
90
|
// For each category...
|
|
120
|
-
Object.keys(
|
|
91
|
+
Object.keys(ALIASES).
|
|
121
92
|
// ...create a partial category...
|
|
122
93
|
map(categoryName => addNewPartialCategory(categoryName)).
|
|
123
94
|
// ...retrieve the original spec...
|
|
124
|
-
map(partialCategory => [partialCategory.spec,
|
|
95
|
+
map(partialCategory => [partialCategory.spec, ALIASES[partialCategory.name]]).
|
|
125
96
|
// ...get all aliases in the category...
|
|
126
97
|
forEach(([partialSpec, originalSpec]) => Object.keys(originalSpec).
|
|
127
98
|
// ...find the ones we are interested in (if any)...
|
|
@@ -146,38 +117,75 @@ function createCategoriesOnTheFly(aliasNames) {
|
|
|
146
117
|
function getDescription(alias) {
|
|
147
118
|
let desc = alias.getSpec().description;
|
|
148
119
|
|
|
149
|
-
Object.
|
|
150
|
-
const repl = constants.DESC_REPLACEMENTS[original];
|
|
120
|
+
Object.entries(getDescReplacements()).forEach(([original, repl]) => {
|
|
151
121
|
desc = desc.split(original).join(repl);
|
|
152
122
|
});
|
|
153
123
|
|
|
154
124
|
return desc;
|
|
155
125
|
}
|
|
156
126
|
|
|
157
|
-
function
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
const indent2 = ' '.repeat(indent1.length + maxNameLen + joiner.length);
|
|
162
|
-
|
|
163
|
-
const headerStyle = category.problematic ? chalk.yellowBright : chalk.cyan;
|
|
164
|
-
const aliasStyle = category.problematic ? chalk.red : chalk.green;
|
|
127
|
+
async function help(...names) {
|
|
128
|
+
const showAll = !names.length;
|
|
129
|
+
const showCategory = (names.length === 1) && hasOwnProperty(ALIASES, names[0]);
|
|
130
|
+
const showAliases = !showAll && !showCategory;
|
|
165
131
|
|
|
166
|
-
|
|
132
|
+
try {
|
|
133
|
+
const sep = '~'.repeat(75);
|
|
134
|
+
const joiner = ' --> ';
|
|
135
|
+
|
|
136
|
+
const matchedCategories = showAliases ?
|
|
137
|
+
createCategoriesOnTheFly(names) :
|
|
138
|
+
Object.entries(ALIASES).
|
|
139
|
+
filter(([categoryName]) => showAll || (categoryName === names[0])).
|
|
140
|
+
map(([name, spec]) => ({name, spec}));
|
|
141
|
+
|
|
142
|
+
const header = !showAll ? `${VERSION_STAMP}\n` : [
|
|
143
|
+
'',
|
|
144
|
+
versionHeader(),
|
|
145
|
+
'',
|
|
146
|
+
' Available aliases',
|
|
147
|
+
'===================',
|
|
148
|
+
'',
|
|
149
|
+
].join('\n');
|
|
150
|
+
const mainSection = matchedCategories.
|
|
151
|
+
filter(category => Object.keys(category.spec).length).
|
|
152
|
+
map(category => helpForCategory(category, joiner)).
|
|
153
|
+
join(`\n\n${chalk.gray(sep)}\n\n`) || chalk.yellowBright(' Nothing to see here :(');
|
|
154
|
+
const footer = showAliases ? '' : [
|
|
155
|
+
'',
|
|
156
|
+
chalk.magenta(sep),
|
|
157
|
+
'',
|
|
158
|
+
'All aliases also accept the following arguments:',
|
|
159
|
+
'--gkcu-debug: Produce verbose, debug-friendly output.',
|
|
160
|
+
'--gkcu-dryrun: Print the command instead of actually running it. (Still experimental.)',
|
|
161
|
+
'--gkcu-sapVersion: Choose a different implementation for the command runner. (Default: 2)',
|
|
162
|
+
'--gkcu-suppressTbj: Suppress the "Terminate batch job (Y/N)?" confirmation on Windows. (Still experimental.)',
|
|
163
|
+
' Does not work with certain types of commands (e.g. `vim`).',
|
|
164
|
+
'',
|
|
165
|
+
wrapLine(
|
|
166
|
+
'(NOTE: All arguments starting with `--gkcu-` will be ignored when substituting input arguments or ' +
|
|
167
|
+
'determining their index.)'),
|
|
168
|
+
'',
|
|
169
|
+
].join('\n');
|
|
170
|
+
|
|
171
|
+
const message = [
|
|
172
|
+
chalk.magenta(header),
|
|
173
|
+
mainSection,
|
|
174
|
+
chalk.gray(footer),
|
|
175
|
+
].join('\n');
|
|
176
|
+
|
|
177
|
+
console.log(message);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
await onError(err);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
167
182
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
'',
|
|
171
|
-
publicAliases.
|
|
172
|
-
map(aliasName => [aliasName, getDescription(category.spec[aliasName])]).
|
|
173
|
-
map(([aliasName, aliasDesc]) => [utils.padRight(aliasName, maxNameLen), wrapMultiline(aliasDesc, indent2)]).
|
|
174
|
-
map(([aliasName, aliasDesc]) => `${indent1}${aliasStyle(aliasName)}${chalk.gray(joiner)}${aliasDesc}`).
|
|
175
|
-
join('\n'),
|
|
176
|
-
].join('\n');
|
|
183
|
+
function helpForCategory(category, joiner) {
|
|
184
|
+
return internal._helpForCategory(category, joiner);
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
function versionHeader() {
|
|
180
|
-
const versionLine = `| ${
|
|
188
|
+
const versionLine = `| ${VERSION_STAMP} |`;
|
|
181
189
|
const len = versionLine.length - 2;
|
|
182
190
|
const outerLine = ` ${'-'.repeat(len)} `;
|
|
183
191
|
const innerLine = `|${' '.repeat(len)}|`;
|
|
@@ -194,7 +202,7 @@ function versionHeader() {
|
|
|
194
202
|
function wrapMultiline(input, wrapIndent) {
|
|
195
203
|
return input.
|
|
196
204
|
split('\n').
|
|
197
|
-
map(l =>
|
|
205
|
+
map(l => wrapLine(l, wrapIndent)).
|
|
198
206
|
map((l, i) => (i === 0) ? l : `${wrapIndent}${l}`).
|
|
199
207
|
join('\n');
|
|
200
208
|
}
|