1 | import { console } from './console.js';
|
2 | import { addPathsToGlobalImports, addPathsToGlobalImportsResultToTable, listGlobalImports, listGlobalImportsResultToTable, removePathsFromGlobalImports, } from './link.js';
|
3 | import { CheckFailed } from './util/errors.js';
|
4 | import { tableToLines } from './util/table.js';
|
5 | export function commandLink(prog) {
|
6 | const linkCommand = prog
|
7 | .command('link')
|
8 | .description('Link dictionaries and other settings to the cspell global config.');
|
9 | linkCommand
|
10 | .command('list', { isDefault: true })
|
11 | .alias('ls')
|
12 | .description('List currently linked configurations.')
|
13 | .action(async () => {
|
14 | const imports = await listGlobalImports();
|
15 | const table = listGlobalImportsResultToTable(imports.list);
|
16 | tableToLines(table).forEach((line) => console.log(line));
|
17 | return;
|
18 | });
|
19 | linkCommand
|
20 | .command('add <dictionaries...>')
|
21 | .alias('a')
|
22 | .description('Add dictionaries any other settings to the cspell global config.')
|
23 | .action(async (dictionaries) => {
|
24 | const r = await addPathsToGlobalImports(dictionaries);
|
25 | const table = addPathsToGlobalImportsResultToTable(r);
|
26 | console.log('Adding:');
|
27 | tableToLines(table).forEach((line) => console.log(line));
|
28 | if (r.error) {
|
29 | throw new CheckFailed(r.error, 1);
|
30 | }
|
31 | return;
|
32 | });
|
33 | linkCommand
|
34 | .command('remove <paths...>')
|
35 | .alias('r')
|
36 | .description('Remove matching paths / packages from the global config.')
|
37 | .action(async (dictionaries) => {
|
38 | const r = await removePathsFromGlobalImports(dictionaries);
|
39 | console.log('Removing:');
|
40 | if (r.error) {
|
41 | throw new CheckFailed(r.error, 1);
|
42 | }
|
43 | r.removed.map((f) => console.log(f));
|
44 | return;
|
45 | });
|
46 | return linkCommand;
|
47 | }
|
48 |
|
\ | No newline at end of file |