Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist/
2 changes: 2 additions & 0 deletions cli/.mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
bun = "latest"
91 changes: 91 additions & 0 deletions cli/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "techulus-cli",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "node --import tsx src/main.ts",
"build": "bun build src/main.ts --compile --outfile dist/tcloud",
"build:linux-x64": "bun build src/main.ts --compile --target=bun-linux-x64 --outfile dist/tcloud-linux-x64",
"build:linux-arm64": "bun build src/main.ts --compile --target=bun-linux-arm64 --outfile dist/tcloud-linux-arm64",
"build:darwin-x64": "bun build src/main.ts --compile --target=bun-darwin-x64 --outfile dist/tcloud-darwin-x64",
"build:darwin-arm64": "bun build src/main.ts --compile --target=bun-darwin-arm64 --outfile dist/tcloud-darwin-arm64",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"yaml": "^2.8.2",
"zod": "^4.3.5"
},
"devDependencies": {
"@types/node": "^22.17.0",
"tsx": "^4.19.2",
"typescript": "^5.9.2"
}
}
64 changes: 64 additions & 0 deletions cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";

export type CliConfig = {
host: string;
apiKey: string;
keyId?: string;
keyName?: string | null;
user?: {
id: string;
email: string;
name: string;
};
};

function getConfigRoot() {
if (process.env.XDG_CONFIG_HOME) {
return process.env.XDG_CONFIG_HOME;
}

if (process.platform === "darwin") {
return path.join(os.homedir(), "Library", "Application Support");
}

if (process.platform === "win32" && process.env.APPDATA) {
return process.env.APPDATA;
}

return path.join(os.homedir(), ".config");
}

export function getConfigDir() {
return path.join(getConfigRoot(), "techulus-cloud-cli");
}

export function getConfigPath() {
return path.join(getConfigDir(), "config.json");
}

export async function readConfig(): Promise<CliConfig | null> {
try {
const contents = await readFile(getConfigPath(), "utf8");
return JSON.parse(contents) as CliConfig;
} catch {
return null;
}
}

export async function writeConfig(config: CliConfig) {
const dir = getConfigDir();
const file = getConfigPath();

await mkdir(dir, { recursive: true, mode: 0o700 });
await writeFile(file, JSON.stringify(config, null, 2), {
encoding: "utf8",
mode: 0o600,
});
await chmod(file, 0o600);
}

export async function deleteConfig() {
await rm(getConfigPath(), { force: true });
}
Loading
Loading