-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
56 lines (50 loc) · 1.71 KB
/
main.ts
File metadata and controls
56 lines (50 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as cmd from 'npm:cmd-ts';
import manifest from './deno.json' with {type: 'json'};
import $ from '@david/dax';
const _args = {
rest: cmd.rest({
displayName: 'rest of args',
description: 'Everything else is captured here'
})
}
const restoreCmd = cmd.command({
name: 'restore',
args: {},
handler(args) {
console.log(`This is the restore subcommand: ${args}`);
}
});
const saveCmd = cmd.command({
name: 'save',
args: {},
async handler(args) {
console.log(`This is the save subcommand: ${args}`);
const gitConfig = await $`git config --list -z`.stdout('piped');
const gitConfigValues = gitConfig.stdout.split('\0').map(pair => {
const split = pair.indexOf('\n');
const sectionKey = pair.slice(0, split);
const splitA = sectionKey.indexOf('.');
const splitB = sectionKey.lastIndexOf('.');
const section = sectionKey.slice(0, splitA);
const key = sectionKey.slice(splitB + 1);
const subsection = splitA === splitB ? undefined : sectionKey.slice(splitA + 1, splitB);
const value = pair.slice(split + 1);
return {
section, subsection, key, value
};
});
// Build into an object:
section(name, subsection name)
console.dir(gitConfigValues);
}
});
const gitAugment = cmd.subcommands({
name: 'git-augment',
cmds: {
[restoreCmd.name]: restoreCmd,
[saveCmd.name]: saveCmd,
},
description: 'Save and restore an overlay of additions and modifications to a repository without committing them.',
version: manifest.version,
});
cmd.run(gitAugment, Deno.args);