swadhinbiswas ✨ feat(cli): harden auth, TLS, retries, and repo parsing · 1/22/2026
416b898
63 lines · 1.4 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
57
58
59
60
61
62
63
/**
 * CLI Configuration
 * Store and retrieve CLI settings
 */

import Conf from "conf";

interface OchConfig {
  serverUrl: string;
  token: string;
  username?: string;
  defaultBranch?: string;
  caFile?: string;
  insecure?: boolean;
}

const config = new Conf<OchConfig>({
  projectName: "opencodehub-cli",
  defaults: {
    serverUrl: "",
    token: "",
    defaultBranch: "main",
    caFile: "",
    insecure: false,
  },
});

export function getConfig(): OchConfig {
  return {
    serverUrl: config.get("serverUrl"),
    token: config.get("token"),
    username: config.get("username"),
    defaultBranch: config.get("defaultBranch"),
    caFile: config.get("caFile"),
    insecure: config.get("insecure"),
  };
}

export function saveConfig(updates: Partial<OchConfig>): void {
  if (updates.serverUrl !== undefined) {
    config.set("serverUrl", updates.serverUrl);
  }
  if (updates.token !== undefined) {
    config.set("token", updates.token);
  }
  if (updates.username !== undefined) {
    config.set("username", updates.username);
  }
  if (updates.defaultBranch !== undefined) {
    config.set("defaultBranch", updates.defaultBranch);
  }
  if (updates.caFile !== undefined) {
    config.set("caFile", updates.caFile);
  }
  if (updates.insecure !== undefined) {
    config.set("insecure", updates.insecure);
  }
}

export function clearConfig(): void {
  config.clear();
}