UNPKG

@huangjunsen/vault-cli

Version:

macOS vault CLI: hide/unhide directories with .noindex and manage encrypted sparsebundles

78 lines (68 loc) 2.09 kB
const fs = require('fs'); const path = require('path'); const { printInfo, printSuccess, printError, pathExists } = require('../utils'); function hiddenPathFor(targetPath) { const parent = path.dirname(targetPath); const base = path.basename(targetPath); return path.join(parent, `.${base}.noindex`); } function doOff(t, { verbose, dryRun }) { const target = t.path; const hidden = hiddenPathFor(target); if (pathExists(hidden)) { if (verbose) printInfo(`Already hidden: ${hidden}`); printSuccess(`OFF: ${t.name} hidden at ${hidden}`); return; } if (!pathExists(target)) { throw new Error(`Path not found: ${target}`); } if (dryRun) { printInfo(`[dry-run] rename ${target} -> ${hidden}`); } else { fs.renameSync(target, hidden); printSuccess(`OFF: Renamed to ${hidden}`); } } function doOn(t, { verbose, dryRun }) { const target = t.path; const hidden = hiddenPathFor(target); if (pathExists(target)) { if (verbose) printInfo(`Already visible: ${target}`); printSuccess(`ON: ${t.name} visible at ${target}`); return; } if (!pathExists(hidden)) { throw new Error(`Hidden path not found: ${hidden}`); } if (dryRun) { printInfo(`[dry-run] rename ${hidden} -> ${target}`); } else { fs.renameSync(hidden, target); printSuccess(`ON: Restored to ${target}`); } } function doStatus(t, { verbose }) { const target = t.path; const hidden = hiddenPathFor(target); if (pathExists(hidden)) { console.log(`${t.name} [rename_noindex]: OFF (hidden) -> ${hidden}`); } else if (pathExists(target)) { console.log(`${t.name} [rename_noindex]: ON (visible) -> ${target}`); } else { console.log(`${t.name} [rename_noindex]: MISSING (neither visible nor hidden)`); } } function handle(cmd, t, opts) { switch (cmd) { case 'off': return doOff(t, opts); case 'on': return doOn(t, opts); case 'status': return doStatus(t, opts); default: throw new Error(`Unsupported command for rename_noindex: ${cmd}`); } } module.exports = { handle };