Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

config.ts 1.3 KB

You have to be logged in to leave a comment. Sign In
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
64
  1. import sade from "sade";
  2. // @ts-expect-error: vite-node makes the var available but the typescript compiler doesn't see them
  3. import { config, ready } from "$lib/server/config";
  4. const prog = sade("config");
  5. await ready;
  6. prog
  7. .command("clear")
  8. .describe("Clear all config keys")
  9. .action(async () => {
  10. console.log("Clearing config...");
  11. await clear();
  12. });
  13. prog
  14. .command("add <key> <value>")
  15. .describe("Add a new config key")
  16. .action(async (key: string, value: string) => {
  17. await add(key, value);
  18. });
  19. prog
  20. .command("remove <key>")
  21. .describe("Remove a config key")
  22. .action(async (key: string) => {
  23. console.log(`Removing ${key}`);
  24. await remove(key);
  25. process.exit(0);
  26. });
  27. prog
  28. .command("help")
  29. .describe("Show help information")
  30. .action(() => {
  31. prog.help();
  32. process.exit(0);
  33. });
  34. async function clear() {
  35. await config.clear();
  36. process.exit(0);
  37. }
  38. async function add(key: string, value: string) {
  39. if (!key || !value) {
  40. console.error("Key and value are required");
  41. process.exit(1);
  42. }
  43. await config.set(key as keyof typeof config.keysFromEnv, value);
  44. process.exit(0);
  45. }
  46. async function remove(key: string) {
  47. if (!key) {
  48. console.error("Key is required");
  49. process.exit(1);
  50. }
  51. await config.delete(key as keyof typeof config.keysFromEnv);
  52. process.exit(0);
  53. }
  54. // Parse arguments and handle help automatically
  55. prog.parse(process.argv);
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...