UNPKG

2.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.GitConfigScope = void 0;
4const ConfigList_1 = require("../responses/ConfigList");
5const utils_1 = require("../utils");
6var GitConfigScope;
7(function (GitConfigScope) {
8 GitConfigScope["system"] = "system";
9 GitConfigScope["global"] = "global";
10 GitConfigScope["local"] = "local";
11 GitConfigScope["worktree"] = "worktree";
12})(GitConfigScope = exports.GitConfigScope || (exports.GitConfigScope = {}));
13function asConfigScope(scope, fallback) {
14 if (typeof scope === 'string' && GitConfigScope.hasOwnProperty(scope)) {
15 return scope;
16 }
17 return fallback;
18}
19function addConfigTask(key, value, append, scope) {
20 const commands = ['config', `--${scope}`];
21 if (append) {
22 commands.push('--add');
23 }
24 commands.push(key, value);
25 return {
26 commands,
27 format: 'utf-8',
28 parser(text) {
29 return text;
30 }
31 };
32}
33function getConfigTask(key, scope) {
34 const commands = ['config', '--null', '--show-origin', '--get-all', key];
35 if (scope) {
36 commands.splice(1, 0, `--${scope}`);
37 }
38 return {
39 commands,
40 format: 'utf-8',
41 parser(text) {
42 return ConfigList_1.configGetParser(text, key);
43 }
44 };
45}
46function listConfigTask(scope) {
47 const commands = ['config', '--list', '--show-origin', '--null'];
48 if (scope) {
49 commands.push(`--${scope}`);
50 }
51 return {
52 commands,
53 format: 'utf-8',
54 parser(text) {
55 return ConfigList_1.configListParser(text);
56 },
57 };
58}
59function default_1() {
60 return {
61 addConfig(key, value, ...rest) {
62 return this._runTask(addConfigTask(key, value, rest[0] === true, asConfigScope(rest[1], GitConfigScope.local)), utils_1.trailingFunctionArgument(arguments));
63 },
64 getConfig(key, scope) {
65 return this._runTask(getConfigTask(key, asConfigScope(scope, undefined)), utils_1.trailingFunctionArgument(arguments));
66 },
67 listConfig(...rest) {
68 return this._runTask(listConfigTask(asConfigScope(rest[0], undefined)), utils_1.trailingFunctionArgument(arguments));
69 },
70 };
71}
72exports.default = default_1;
73//# sourceMappingURL=config.js.map
\No newline at end of file