Skip to content

Commit 5aa6e49

Browse files
committed
open-file support for settings and appdata
1 parent 5db34ca commit 5aa6e49

File tree

1 file changed

+79
-47
lines changed

1 file changed

+79
-47
lines changed

src/main/cli.ts

Lines changed: 79 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function parseCLIArgs(argv: string[]) {
201201
yargs
202202
.positional('action', {
203203
describe: 'Setting action',
204-
choices: ['list', 'set', 'unset'],
204+
choices: ['list', 'set', 'unset', 'open-file'],
205205
default: 'list'
206206
})
207207
.option('project', {
@@ -228,6 +228,9 @@ export function parseCLIArgs(argv: string[]) {
228228
case 'unset':
229229
handleConfigUnsetCommand(argv);
230230
break;
231+
case 'open-file':
232+
handleConfigOpenFileCommand(argv);
233+
break;
231234
default:
232235
console.log('Invalid input for "config" command.');
233236
break;
@@ -240,7 +243,7 @@ export function parseCLIArgs(argv: string[]) {
240243
yargs => {
241244
yargs.positional('action', {
242245
describe: 'App data action',
243-
choices: ['list'],
246+
choices: ['list', 'open-file'],
244247
default: 'list'
245248
});
246249
},
@@ -252,6 +255,9 @@ export function parseCLIArgs(argv: string[]) {
252255
case 'list':
253256
handleAppDataListCommand(argv);
254257
break;
258+
case 'open-file':
259+
handleAppDataOpenFileCommand(argv);
260+
break;
255261
default:
256262
console.log('Invalid input for "appdata" command.');
257263
break;
@@ -264,7 +270,7 @@ export function parseCLIArgs(argv: string[]) {
264270
yargs => {
265271
yargs.positional('action', {
266272
describe: 'Logs action',
267-
choices: ['show', 'open'],
273+
choices: ['show', 'open-file'],
268274
default: 'show'
269275
});
270276
},
@@ -276,8 +282,8 @@ export function parseCLIArgs(argv: string[]) {
276282
case 'show':
277283
handleLogsShowCommand(argv);
278284
break;
279-
case 'open':
280-
handleLogsOpenCommand(argv);
285+
case 'open-file':
286+
handleLogsOpenFileCommand(argv);
281287
break;
282288
default:
283289
console.log('Invalid input for "logs" command.');
@@ -913,10 +919,28 @@ export async function handleEnvSetSystemPythonPathCommand(argv: any) {
913919
userSettings.save();
914920
}
915921

922+
function getProjectPathForConfigCommand(argv: any): string | undefined {
923+
let projectPath = undefined;
924+
if (argv.project || argv.projectPath) {
925+
projectPath = argv.projectPath
926+
? path.resolve(argv.projectPath)
927+
: process.cwd();
928+
if (
929+
argv.projectPath &&
930+
!(fs.existsSync(projectPath) && fs.statSync(projectPath).isDirectory())
931+
) {
932+
console.error(`Invalid project path! "${projectPath}"`);
933+
process.exit(1);
934+
}
935+
}
936+
937+
return projectPath;
938+
}
939+
916940
function handleConfigListCommand(argv: any) {
917941
const listLines: string[] = [];
918942

919-
let projectPath = argv.projectPath
943+
const projectPath = argv.projectPath
920944
? path.resolve(argv.projectPath)
921945
: process.cwd();
922946

@@ -986,23 +1010,7 @@ function handleConfigSetCommand(argv: any) {
9861010
return { key: argv._[1], value: value };
9871011
};
9881012

989-
let projectPath = '';
990-
let isProjectSetting = false;
991-
992-
if (argv.project || argv.projectPath) {
993-
projectPath = argv.projectPath
994-
? path.resolve(argv.projectPath)
995-
: process.cwd();
996-
if (
997-
argv.projectPath &&
998-
!(fs.existsSync(projectPath) && fs.statSync(projectPath).isDirectory())
999-
) {
1000-
console.error(`Invalid project path! "${projectPath}"`);
1001-
return;
1002-
}
1003-
1004-
isProjectSetting = true;
1005-
}
1013+
const projectPath = getProjectPathForConfigCommand(argv);
10061014

10071015
let key, value;
10081016
try {
@@ -1024,7 +1032,7 @@ function handleConfigSetCommand(argv: any) {
10241032
return;
10251033
}
10261034

1027-
if (isProjectSetting) {
1035+
if (projectPath) {
10281036
const setting = userSettings.settings[key];
10291037
if (!setting.wsOverridable) {
10301038
console.error(`Setting "${key}" is not overridable by project.`);
@@ -1041,7 +1049,7 @@ function handleConfigSetCommand(argv: any) {
10411049

10421050
console.log(
10431051
`${
1044-
isProjectSetting ? 'Project' : 'Global'
1052+
projectPath ? 'Project' : 'Global'
10451053
} setting "${key}" set to "${value}" successfully.`
10461054
);
10471055
}
@@ -1056,23 +1064,7 @@ function handleConfigUnsetCommand(argv: any) {
10561064
return argv._[1];
10571065
};
10581066

1059-
let projectPath = '';
1060-
let isProjectSetting = false;
1061-
1062-
if (argv.project || argv.projectPath) {
1063-
projectPath = argv.projectPath
1064-
? path.resolve(argv.projectPath)
1065-
: process.cwd();
1066-
if (
1067-
argv.projectPath &&
1068-
!(fs.existsSync(projectPath) && fs.statSync(projectPath).isDirectory())
1069-
) {
1070-
console.error(`Invalid project path! "${projectPath}"`);
1071-
return;
1072-
}
1073-
1074-
isProjectSetting = true;
1075-
}
1067+
const projectPath = getProjectPathForConfigCommand(argv);
10761068

10771069
let key = parseKey();
10781070

@@ -1085,7 +1077,7 @@ function handleConfigUnsetCommand(argv: any) {
10851077
return;
10861078
}
10871079

1088-
if (isProjectSetting) {
1080+
if (projectPath) {
10891081
const setting = userSettings.settings[key];
10901082
if (!setting.wsOverridable) {
10911083
console.error(`Setting "${key}" is not overridable by project.`);
@@ -1101,12 +1093,30 @@ function handleConfigUnsetCommand(argv: any) {
11011093
}
11021094

11031095
console.log(
1104-
`${isProjectSetting ? 'Project' : 'Global'} setting "${key}" reset to ${
1105-
isProjectSetting ? 'global ' : ''
1096+
`${projectPath ? 'Project' : 'Global'} setting "${key}" reset to ${
1097+
projectPath ? 'global ' : ''
11061098
}default successfully.`
11071099
);
11081100
}
11091101

1102+
function handleConfigOpenFileCommand(argv: any) {
1103+
const projectPath = getProjectPathForConfigCommand(argv);
1104+
const settingsFilePath = projectPath
1105+
? WorkspaceSettings.getWorkspaceSettingsPath(projectPath)
1106+
: UserSettings.getUserSettingsPath();
1107+
1108+
console.log(`Settings file path: ${settingsFilePath}`);
1109+
1110+
if (
1111+
!(fs.existsSync(settingsFilePath) && fs.statSync(settingsFilePath).isFile())
1112+
) {
1113+
console.log('Settings file does not exist!');
1114+
return;
1115+
}
1116+
1117+
shell.openPath(settingsFilePath);
1118+
}
1119+
11101120
function handleAppDataListCommand(argv: any) {
11111121
const listLines: string[] = [];
11121122

@@ -1130,6 +1140,20 @@ function handleAppDataListCommand(argv: any) {
11301140
console.log(listLines.join('\n'));
11311141
}
11321142

1143+
function handleAppDataOpenFileCommand(argv: any) {
1144+
const appDataFilePath = ApplicationData.getAppDataPath();
1145+
console.log(`App data file path: ${appDataFilePath}`);
1146+
1147+
if (
1148+
!(fs.existsSync(appDataFilePath) && fs.statSync(appDataFilePath).isFile())
1149+
) {
1150+
console.log('App data file does not exist!');
1151+
return;
1152+
}
1153+
1154+
shell.openPath(appDataFilePath);
1155+
}
1156+
11331157
function handleLogsShowCommand(argv: any) {
11341158
const logFilePath = getLogFilePath();
11351159
console.log(`Log file path: ${logFilePath}`);
@@ -1143,8 +1167,16 @@ function handleLogsShowCommand(argv: any) {
11431167
console.log(logs.toString());
11441168
}
11451169

1146-
function handleLogsOpenCommand(argv: any) {
1147-
shell.openPath(getLogFilePath());
1170+
function handleLogsOpenFileCommand(argv: any) {
1171+
const logFilePath = getLogFilePath();
1172+
console.log(`Log file path: ${logFilePath}`);
1173+
1174+
if (!(fs.existsSync(logFilePath) && fs.statSync(logFilePath).isFile())) {
1175+
console.log('Log file does not exist!');
1176+
return;
1177+
}
1178+
1179+
shell.openPath(logFilePath);
11481180
}
11491181

11501182
export async function launchCLIinEnvironment(

0 commit comments

Comments
 (0)