mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
fix: enable logging via the --verbose flag (#115)
Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user