Skip to content

Commit 7df69aa

Browse files
committed
fix: added a check to verify whether provided path is directory or not
1 parent bed3ab6 commit 7df69aa

File tree

1 file changed

+15
-3
lines changed
  • packages/contentstack-config/src/commands/config/set

1 file changed

+15
-3
lines changed

packages/contentstack-config/src/commands/config/set/log.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { Command } from '@contentstack/cli-command';
2-
import { cliux, flags, configHandler, FlagInput, messageHandler } from '@contentstack/cli-utilities';
2+
import { cliux, flags, configHandler, FlagInput, messageHandler, CLIError } from '@contentstack/cli-utilities';
33
import { interactive } from '../../../utils';
4+
import { existsSync, statSync } from 'fs';
5+
import { dirname } from 'path';
46

57
export default class LogSetCommand extends Command {
68
static description = 'Set logging configuration for CLI';
79

810
static flags: FlagInput = {
9-
'level': flags.string({
11+
level: flags.string({
1012
description: 'Set the log level for the CLI.',
1113
options: ['debug', 'info', 'warn', 'error'],
1214
}),
13-
'path': flags.string({
15+
path: flags.string({
1416
description: ' Specify the file path where logs should be saved.',
1517
}),
1618
};
@@ -33,6 +35,16 @@ export default class LogSetCommand extends Command {
3335
logPath = await interactive.askLogPath();
3436
}
3537

38+
if (logPath) {
39+
const logDir = dirname(logPath);
40+
// Check if the directory part of the path exists and is actually a file
41+
if (existsSync(logDir) && statSync(logDir).isFile()) {
42+
throw new CLIError({
43+
message: `The directory path '${logDir}' is a file, not a directory. Please provide a valid directory path for the log file.`,
44+
});
45+
}
46+
}
47+
3648
const currentLoggingConfig = configHandler.get('log') || {};
3749
if (logLevel) currentLoggingConfig.level = logLevel;
3850
if (logPath) currentLoggingConfig.path = logPath;

0 commit comments

Comments
 (0)