@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.
Files changed (162) hide show
  1. package/README.md +4 -4
  2. package/bin/aio/__a-builds-dir.js +5 -7
  3. package/bin/aio/aioall.js +5 -5
  4. package/bin/aio/aioatt.js +5 -5
  5. package/bin/aio/aiobd.js +5 -5
  6. package/bin/aio/aiord.js +5 -5
  7. package/bin/aio/aiorm.js +5 -5
  8. package/bin/config/cfgbash.js +3 -4
  9. package/bin/config/cfgbash.wsl.js +3 -4
  10. package/bin/config/cfggit.js +3 -4
  11. package/bin/config/cfggit.wsl.js +4 -5
  12. package/bin/config/cfgvim.js +5 -3
  13. package/bin/docker/dkrall.js +5 -5
  14. package/bin/docker/dkratt.js +5 -5
  15. package/bin/docker/dkrbd.js +5 -5
  16. package/bin/docker/dkrrd.js +5 -5
  17. package/bin/docker/dkrrm.js +5 -5
  18. package/bin/git/__g-pick-branch.js +5 -7
  19. package/bin/git/__g-pick-commit.js +5 -7
  20. package/bin/git/gaa.js +5 -5
  21. package/bin/git/gb.js +5 -5
  22. package/bin/git/gbc.js +5 -5
  23. package/bin/git/gbcm.js +5 -5
  24. package/bin/git/gbd.js +5 -5
  25. package/bin/git/gcl.js +5 -5
  26. package/bin/git/gcm.js +5 -5
  27. package/bin/git/gcma.js +5 -5
  28. package/bin/git/gcmane.js +5 -5
  29. package/bin/git/gcmf.js +5 -5
  30. package/bin/git/gcmfc.js +5 -5
  31. package/bin/git/gcmfs.js +5 -5
  32. package/bin/git/gcmi.js +5 -5
  33. package/bin/git/gcmia.js +5 -5
  34. package/bin/git/gcmiane.js +5 -5
  35. package/bin/git/gcmif.js +5 -5
  36. package/bin/git/gcmifc.js +5 -5
  37. package/bin/git/gcmifs.js +5 -5
  38. package/bin/git/gco.js +5 -5
  39. package/bin/git/gcoghpr-cleanup.js +5 -5
  40. package/bin/git/gcoghpr.js +5 -7
  41. package/bin/git/gcom.js +5 -5
  42. package/bin/git/gcopr.js +5 -5
  43. package/bin/git/gcp.js +5 -5
  44. package/bin/git/gcpa.js +5 -5
  45. package/bin/git/gcpc.js +5 -5
  46. package/bin/git/gcpx.js +5 -5
  47. package/bin/git/gcpxl.js +5 -5
  48. package/bin/git/gd.js +5 -5
  49. package/bin/git/gd1.js +5 -5
  50. package/bin/git/gdefb.js +5 -5
  51. package/bin/git/gdh.js +5 -5
  52. package/bin/git/gdn.js +5 -5
  53. package/bin/git/gdn1.js +5 -5
  54. package/bin/git/gdnh.js +5 -5
  55. package/bin/git/gl.js +5 -5
  56. package/bin/git/gl1.js +5 -5
  57. package/bin/git/gl1g.js +5 -5
  58. package/bin/git/gmt.js +5 -5
  59. package/bin/git/gngprh.js +5 -5
  60. package/bin/git/gngprm.js +5 -5
  61. package/bin/git/gp.js +5 -5
  62. package/bin/git/gp1.js +5 -5
  63. package/bin/git/gpf.js +5 -5
  64. package/bin/git/gpr.js +5 -5
  65. package/bin/git/gpro.js +5 -5
  66. package/bin/git/gprom.js +5 -5
  67. package/bin/git/gpru.js +5 -5
  68. package/bin/git/gprum.js +5 -5
  69. package/bin/git/grb.js +5 -5
  70. package/bin/git/grba.js +5 -5
  71. package/bin/git/grbc.js +5 -5
  72. package/bin/git/grbi.js +5 -5
  73. package/bin/git/grbia.js +5 -5
  74. package/bin/git/grbin.js +5 -5
  75. package/bin/git/grbm.js +5 -5
  76. package/bin/git/grs.js +5 -5
  77. package/bin/git/grs1.js +5 -5
  78. package/bin/git/gs.js +5 -5
  79. package/bin/git/gsh.js +5 -5
  80. package/bin/git/gshn.js +5 -5
  81. package/bin/git/gst.js +5 -5
  82. package/bin/git/gstk.js +5 -5
  83. package/bin/git/gstl.js +5 -5
  84. package/bin/git/gstp.js +5 -5
  85. package/bin/git/gsync.js +5 -5
  86. package/bin/misc/alv.js +1 -2
  87. package/bin/misc/halp.js +2 -2
  88. package/bin/misc/ll.darwin.js +5 -5
  89. package/bin/misc/ll.js +5 -5
  90. package/bin/misc/lla.darwin.js +5 -5
  91. package/bin/misc/lla.js +5 -5
  92. package/bin/misc/osv.darwin.js +5 -5
  93. package/bin/misc/osv.js +5 -5
  94. package/bin/misc/osv.win32.js +5 -5
  95. package/bin/misc/salfup.js +5 -5
  96. package/bin/node/nad.js +5 -5
  97. package/bin/node/naga.js +5 -5
  98. package/bin/node/nap.js +5 -5
  99. package/bin/node/niin.js +5 -5
  100. package/bin/node/nls.js +5 -5
  101. package/bin/node/nls1.js +5 -5
  102. package/bin/node/nlsg.js +5 -5
  103. package/bin/node/nlsg1.js +5 -5
  104. package/bin/node/nr.js +5 -5
  105. package/bin/node/nrd.js +5 -5
  106. package/bin/node/nrin.js +5 -5
  107. package/bin/node/nrp.js +5 -5
  108. package/bin/node/nrx.js +5 -5
  109. package/bin/node/ns.js +5 -5
  110. package/bin/node/nsin.js +5 -5
  111. package/bin/node/nsx.js +5 -5
  112. package/bin/node/nt.js +5 -5
  113. package/bin/node/ntin.js +5 -5
  114. package/bin/node/ntx.js +5 -5
  115. package/bin/node/nua.js +5 -5
  116. package/bin/node/nud.js +5 -5
  117. package/bin/node/nup.js +5 -5
  118. package/bin/node/nv.js +5 -5
  119. package/bin/node/nvls.js +5 -5
  120. package/bin/node/nvls.win32.js +5 -5
  121. package/bin/node/nvlsa.js +5 -5
  122. package/bin/node/nvlsa.win32.js +5 -5
  123. package/bin/node/nvmup.js +5 -5
  124. package/bin/node/nvmup.win32.js +5 -5
  125. package/bin/node/nvu.js +5 -7
  126. package/bin/node/srv.js +5 -5
  127. package/bin/node/srvw.js +5 -5
  128. package/bin/node/yad.js +5 -5
  129. package/bin/node/yaga.js +5 -5
  130. package/bin/node/yap.js +5 -5
  131. package/bin/node/yiin.js +5 -5
  132. package/bin/node/yls.js +5 -5
  133. package/bin/node/yls1.js +5 -5
  134. package/bin/node/ylsg.js +5 -5
  135. package/bin/node/ylsg1.js +5 -5
  136. package/bin/node/yr.js +5 -5
  137. package/bin/node/yrd.js +5 -5
  138. package/bin/node/yrin.js +5 -5
  139. package/bin/node/yrp.js +5 -5
  140. package/bin/node/yrx.js +5 -5
  141. package/bin/node/ys.js +5 -5
  142. package/bin/node/ysin.js +5 -5
  143. package/bin/node/ysx.js +5 -5
  144. package/bin/node/yt.js +5 -5
  145. package/bin/node/ytin.js +5 -5
  146. package/bin/node/ytx.js +5 -5
  147. package/bin/node/yua.js +5 -5
  148. package/bin/node/yud.js +5 -5
  149. package/bin/node/yup.js +5 -5
  150. package/lib/alias-scripts/a-builds-dir.js +65 -45
  151. package/lib/alias-scripts/g-pick-branch.js +44 -25
  152. package/lib/alias-scripts/g-pick-commit.js +44 -25
  153. package/lib/alias-scripts/gcoghpr.js +182 -195
  154. package/lib/alias-scripts/nvu.js +57 -49
  155. package/lib/alias.js +4 -5
  156. package/lib/constants.js +68 -47
  157. package/lib/helper.js +96 -88
  158. package/lib/utils.js +113 -58
  159. package/package.json +8 -6
  160. package/scripts/build.js +11 -10
  161. package/scripts/platformize-bin.js +7 -7
  162. 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
- const utils = require('./utils');
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 = utils.getPlatform())/* IAliasSpec */ {
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
- module.exports = {
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
- const path = require('path');
5
- const pkg = require('../package.json');
6
- const {Alias, AliasDefault, AliasSpec, AliasSpecDefault, AliasUnknown} = require('./alias');
7
- const {PR_LOCAL_BRANCH_PREFIX, PR_REMOTE_ALIAS_PREFIX} = require('./alias-scripts/gcoghpr');
8
- const utils = require('./utils');
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 VERSION_STAMP = `${pkg.name} v${pkg.version}`;
12
- const ROOT_DIR = path.resolve(__dirname, '..');
13
- const BIN_DIR = path.join(ROOT_DIR, 'bin');
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 = {}) => utils.stripIndentation(`
51
+ const DEF_CODE = AliasSpecDefault.DEF_CODE = (cmd, cfg = {}) => stripIndentation(`
46
52
  #!/usr/bin/env node
47
- 'use strict';
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 = module.exports = '${cmd.replace(/'/g, '\\\'')}';
50
- if (require.main === module) {
51
- const {commandUtils} = require('@gkalpak/cli-utils');
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
- utils.stripIndentation(`
67
+ stripIndentation(`
62
68
  #!/usr/bin/env node
63
- 'use strict';
64
- const utils = require('../../lib/utils');
69
+ import {stripIndentation} from '../../lib/utils.js';
65
70
  /* eslint-disable max-len */
66
- console.log(utils.stripIndentation(\`
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
- utils.stripIndentation(`
94
+ stripIndentation(`
90
95
  #!/usr/bin/env node
91
- 'use strict';
92
- const utils = require('../../lib/utils');
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) => utils.stripIndentation(`
118
+ const SCRIPT_BACKED_CODE = (scriptName, desc) => stripIndentation(`
115
119
  #!/usr/bin/env node
116
- 'use strict';
117
- module.exports = '${desc.replace(/'/g, '\\\'')}';
118
- if (require.main === module) {
119
- const {commandUtils} = require('@gkalpak/cli-utils');
120
- const {onError} = require('../../lib/utils');
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(utils.stripIndentation(`
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-core.exe'),
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
- utils.stripIndentation(`
482
+ stripIndentation(`
481
483
  #!/usr/bin/env node
482
- 'use strict';
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(require('fs').readFileSync(\`\${__dirname}/../../lib/assets/vimrc.txt\`, 'utf8').trim() + '\\n');
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 ${pkg.name} $*`),
515
+ salfup: new AliasDefault(`npm install --global ${__pkg.name} $*`),
512
516
 
513
517
  // VERSION
514
518
  alv: new Alias(new AliasSpec(
515
- utils.stripIndentation(`
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 ${pkg.name}.`)),
523
+ `Display the installed version of ${__pkg.name}.`)),
521
524
 
522
525
  // HELP
523
526
  halp: new Alias(new AliasSpec(
524
- utils.stripIndentation(`
527
+ stripIndentation(`
525
528
  #!/usr/bin/env node
526
- 'use strict';
527
- require('../../lib/helper').help(...process.argv.slice(2));
529
+ import {help} from '../../lib/helper.js';
530
+ help(...process.argv.slice(2));
528
531
  `),
529
- utils.stripIndentation(`
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
- module.exports = {
548
+ export {
543
549
  ALIASES,
544
550
  BIN_DIR,
545
551
  DEF_CODE,
546
- DESC_REPLACEMENTS,
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
- const chalk = require('chalk');
5
- const {AliasUnknown} = require('./alias');
6
- const constants = require('./constants');
7
- const utils = require('./utils');
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
- const helper = module.exports = {
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: _help,
40
+ help,
36
41
 
37
- /** Exposed for testing purposes only. */
38
- _helpForCategory: helpForCategory,
42
+ // Exposed for testing purposes only.
43
+ internal as _testing,
39
44
  };
40
45
 
41
- // Functions - Definitions
42
- function _help(...names) {
43
- const showAll = !names.length;
44
- const showCategory = (names.length === 1) && constants.ALIASES.hasOwnProperty(names[0]);
45
- const showAliases = !showAll && !showCategory;
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
- return Promise.resolve().
48
- then(() => {
49
- const sep = '~'.repeat(75);
50
- const joiner = ' --> ';
51
-
52
- const matchedCategories = showAliases ?
53
- createCategoriesOnTheFly(names) :
54
- Object.keys(constants.ALIASES).
55
- filter(categoryName => showAll || (categoryName === names[0])).
56
- map(categoryName => ({name: categoryName, spec: constants.ALIASES[categoryName]}));
57
-
58
- const header = !showAll ? `${constants.VERSION_STAMP}\n` : [
59
- '',
60
- versionHeader(),
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(constants.ALIASES).
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, constants.ALIASES[partialCategory.name]]).
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.keys(constants.DESC_REPLACEMENTS).forEach(original => {
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 helpForCategory(category, joiner) {
158
- const publicAliases = Object.keys(category.spec).filter(aliasName => !/^__/.test(aliasName));
159
- const maxNameLen = Math.max(...publicAliases.map(a => a.length));
160
- const indent1 = ' '.repeat(2);
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
- const headerText = `${category.name} aliases${category.partial ? ' subset' : ''}:`;
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
- return [
169
- headerStyle(utils.capitalize(headerText)),
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 = `| ${constants.VERSION_STAMP} |`;
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 => utils.wrapLine(l, wrapIndent)).
205
+ map(l => wrapLine(l, wrapIndent)).
198
206
  map((l, i) => (i === 0) ? l : `${wrapIndent}${l}`).
199
207
  join('\n');
200
208
  }