Skip to content

Commit 3fdfbed

Browse files
committed
Add more option handling logic
1 parent 83d60bd commit 3fdfbed

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

extension.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ function handleBooleanFlags () {
2020
'conf',
2121
'once',
2222
'no-escape',
23-
'overwrite'
23+
'overwrite',
24+
'excludeReg',
25+
'startLine',
26+
'endLine',
2427
];
2528

2629
return new Promise((resolve, reject) => {
@@ -73,15 +76,25 @@ const activate = (context) => {
7376
const disposable = vscode.commands.registerCommand(
7477
"code-replacer-vscode-plugin.entry",
7578
async function () {
79+
if (!vscode.window.activeTextEditor || !vscode.window.activeTextEditor.document) {
80+
vscode.window.showErrorMessage("Jobs canceled. open the source file first.");
81+
return;
82+
}
83+
84+
const currentlyOpenTabfilePath =
85+
vscode.window.activeTextEditor.document.fileName;
86+
87+
const currentlyOpenTabfileName = path.basename(currentlyOpenTabfilePath);
88+
7689
const codeReplacerPath = `${__dirname}${path.sep}node_modules${
7790
path.sep
7891
}code-replacer${path.sep}dist`;
7992
const binPath = path.resolve(
80-
`${codeReplacerPath}${path.sep}src${path.sep}index.js`
93+
`${codeReplacerPath}${path.sep}index.js`
8194
);
82-
const envPath = path.resolve(`${codeReplacerPath}${path.sep}src${path.sep}${".env"}`);
95+
const envPath = path.resolve(`${codeReplacerPath}${path.sep}${".env"}`);
8396
const usageLogPath = path.resolve(
84-
`${codeReplacerPath}${path.sep}src${path.sep}usageLog.json`
97+
`${codeReplacerPath}${path.sep}usageLog.json`
8598
);
8699
const workspaceName = vscode.workspace.name;
87100
const workspacePath = vscode.workspace.rootPath;
@@ -91,13 +104,10 @@ const activate = (context) => {
91104
});
92105
const selectedCSV = await getQuickPick({
93106
items: csvFiles,
94-
placeHolder: "Select your csv file.",
107+
placeHolder: "Select your csv file or type esc to pass csv option",
95108
});
96109

97-
const currentlyOpenTabfilePath =
98-
vscode.window.activeTextEditor.document.fileName;
99-
100-
const currentlyOpenTabfileName = path.basename(currentlyOpenTabfilePath);
110+
vscode.window.showInformationMessage("csv option is passed.");
101111

102112
const flags = {
103113
src: currentlyOpenTabfilePath,
@@ -106,11 +116,32 @@ const activate = (context) => {
106116

107117
flags.template = await handleTemplate({ usageLogPath });
108118

119+
if (!flags.template) {
120+
vscode.window.showErrorMessage("Jobs canceled. template value is required argument.");
121+
return;
122+
} else if (!validateTemplate(flags.template)) {
123+
vscode.window.showErrorMessage("Wrong template value. See README.md");
124+
return;
125+
}
126+
109127
const booleanFlags = await handleBooleanFlags();
128+
110129
for (const booleanFlag of booleanFlags.values()) {
111130
flags[booleanFlag] = true;
112131
}
113132

133+
if (flags['excludeReg']) {
134+
flags['excludeReg'] = await getInput({ placeHolder: "Enter excludeReg" });
135+
}
136+
137+
if (flags['startLine']) {
138+
flags['startLine'] = await getInput({ placeHolder: "Enter startLine" });
139+
}
140+
141+
if (flags['endLine']) {
142+
flags['endLine'] = await getInput({ placeHolder: "Enter endLine" });
143+
}
144+
114145
const terminal = vscode.window.activeTerminal
115146
? vscode.window.activeTerminal
116147
: vscode.window.createTerminal();

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"mocha": "^8.1.3",
4444
"typescript": "^4.0.2",
4545
"vscode-test": "^1.4.0",
46-
"code-replacer": "0.0.202"
46+
"code-replacer": "0.0.207"
4747
},
4848
"dependencies": {
4949
"recursive-readdir": "^2.2.2"

util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
}
1212
return result;
1313
},
14+
1415
getInput({ placeHolder, validateInput }) {
1516
return new Promise((resolve, reject) => {
1617
vscode.window

0 commit comments

Comments
 (0)