fix: enable logging via the --verbose flag (#115)

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-12-13 12:29:29 -08:00
committed by GitHub
parent 6f52657217
commit da328aa9b7
3 changed files with 17 additions and 3 deletions
+4
View File
@@ -6,14 +6,18 @@ import { Shell, supportedShells as shells, setupZshDotfiles } from "../utils/she
import { inferShell } from "../utils/shell.js";
import { loadConfig } from "../utils/config.js";
import { Command } from "commander";
import log from "../utils/log.js";
export const supportedShells = shells.join(", ");
type RootCommandOptions = {
shell: Shell | undefined;
verbose: boolean | undefined;
};
export const action = (program: Command) => async (options: RootCommandOptions) => {
if (options.verbose) await log.enable();
await loadConfig(program);
const shell = options.shell ?? ((await inferShell()) as unknown as Shell | undefined);
+1
View File
@@ -20,6 +20,7 @@ program
.version(await getVersion(), "-v, --version", "output the current version")
.action(action(program))
.option("-s, --shell <shell>", `shell to use for command execution, supported shells: ${supportedShells}`)
.option("-V, --verbose", `enable verbose logging`)
.showHelpAfterError("(add --help for additional information)");
program.addCommand(complete);
+12 -3
View File
@@ -6,10 +6,14 @@ import path from "node:path";
import fs from "node:fs";
import fsAsync from "node:fs/promises";
const logTarget = path.join(os.homedir(), ".inshellisense", "inshellisense.log");
const logEnabled = false;
const logFolder = path.join(os.homedir(), ".inshellisense");
const logTarget = path.join(logFolder, "inshellisense.log");
let logEnabled = false;
const reset = async () => {
if (!fs.existsSync(logTarget)) {
await fsAsync.mkdir(logFolder, { recursive: true });
}
await fsAsync.writeFile(logTarget, "");
};
@@ -24,4 +28,9 @@ const debug = (content: object) => {
});
};
export default { reset, debug };
export const enable = async () => {
await reset();
logEnabled = true;
};
export default { reset, debug, enable };