permissions hook helper
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Default config path to ~/.config/chook.toml, remove --config requirement

+12 -15
+12 -15
chook.mjs
··· 1 1 #!/usr/bin/env node 2 2 3 - import { readFileSync } from "fs"; 3 + import { readFileSync, existsSync } from "fs"; 4 4 import { appendFileSync, openSync, closeSync, writeFileSync } from "fs"; 5 5 import { resolve } from "path"; 6 + import { homedir } from "os"; 7 + 8 + const DEFAULT_CONFIG = resolve(homedir(), ".config/chook.toml"); 6 9 7 10 // --- Config loading --- 8 11 ··· 361 364 362 365 function getConfigPath() { 363 366 const idx = args.indexOf("--config"); 364 - return idx >= 0 ? resolve(args[idx + 1]) : null; 365 - } 366 - 367 - function getRequiredConfigPath() { 368 - const p = getConfigPath(); 369 - if (!p) { 370 - console.error("Missing --config <path>"); 371 - process.exit(1); 372 - } 373 - return p; 367 + if (idx >= 0) return resolve(args[idx + 1]); 368 + if (existsSync(DEFAULT_CONFIG)) return DEFAULT_CONFIG; 369 + console.error(`No --config specified and ${DEFAULT_CONFIG} not found.`); 370 + process.exit(1); 374 371 } 375 372 376 373 if (command === "validate") { 377 - const configPath = getRequiredConfigPath(); 374 + const configPath = getConfigPath(); 378 375 try { 379 376 const config = loadConfig(configPath); 380 377 const denyRules = compileRules(config.deny || []); ··· 389 386 process.exit(1); 390 387 } 391 388 } else if (command === "run") { 392 - const configPath = getRequiredConfigPath(); 389 + const configPath = getConfigPath(); 393 390 try { 394 391 const config = loadConfig(configPath); 395 392 const denyRules = compileRules(config.deny || []); ··· 422 419 process.exit(1); 423 420 } 424 421 } else if (command === "allow-last" || command === "deny-last") { 425 - const configPath = getRequiredConfigPath(); 422 + const configPath = getConfigPath(); 426 423 const ruleType = command === "allow-last" ? "allow" : "deny"; 427 424 const config = loadConfig(configPath); 428 425 const auditPath = config.audit?.audit_file; ··· 442 439 console.log(`\n-> Appended to ${configPath}`); 443 440 appendRuleToConfig(configPath, ruleBlock); 444 441 } else if (command === "review") { 445 - const configPath = getRequiredConfigPath(); 442 + const configPath = getConfigPath(); 446 443 const config = loadConfig(configPath); 447 444 const auditPath = config.audit?.audit_file; 448 445 if (!auditPath) {