Simplify apps/cli/ code
- config.ts: Convert arrow functions to function declarations - api-client.ts: Extract duplicated RPCLink logic into buildClient helper - format-error.ts: Add centralized ORPCError handling - complete-login.ts: Remove redundant error handling (now in formatError) - status.ts: Simplify formatRelativeTime, improve whitespace - create.ts: Rename validRoles to VALID_ROLES, add as const, early return - completions.ts: Derive Shell type from SUPPORTED_SHELLS array Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,40 +19,42 @@ const CONFIG_FILE = join(CONFIG_DIR, "credentials.json");
|
||||
/**
|
||||
* Get the path to the config file
|
||||
*/
|
||||
export const getConfigPath = (): string => CONFIG_FILE;
|
||||
export function getConfigPath(): string {
|
||||
return CONFIG_FILE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the config file
|
||||
* Returns null if the file doesn't exist or is invalid
|
||||
*/
|
||||
export const readConfig = async (): Promise<Config | null> => {
|
||||
export async function readConfig(): Promise<Config | null> {
|
||||
try {
|
||||
const data = await readFile(CONFIG_FILE, "utf-8");
|
||||
return JSON.parse(data) as Config;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the config file
|
||||
* Creates the config directory if it doesn't exist
|
||||
*/
|
||||
export const writeConfig = async (config: Config): Promise<void> => {
|
||||
export async function writeConfig(config: Config): Promise<void> {
|
||||
await mkdir(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
||||
await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2), {
|
||||
mode: 0o600,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the config file
|
||||
* Ignores errors if the file doesn't exist
|
||||
*/
|
||||
export const deleteConfig = async (): Promise<void> => {
|
||||
export async function deleteConfig(): Promise<void> {
|
||||
try {
|
||||
await unlink(CONFIG_FILE);
|
||||
} catch {
|
||||
// Ignore if doesn't exist
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user