Skip to content

Commit 1b4603f

Browse files
Propagate changes (#73)
2 parents ad9f635 + 01f34bd commit 1b4603f

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

.changeset/nice-keys-flow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eth-tech-tree": patch
3+
---
4+
5+
Ask user for confirmation before resetting their challenge

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Submit a challenge:
2020
npx eth-tech-tree submit CHALLENGE_NAME CONTRACT_ADDRESS
2121
```
2222

23+
Reset your user state (it will re-prompt you for your address and install location):
24+
```bash
25+
npx eth-tech-tree reset
26+
```
27+
2328
## Development
2429
Clone and `cd` into the repo then run this CLI application with the following commands
2530
- `yarn install`

src/index.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ export class TechTree {
129129

130130
getChallengeMessage(node: TreeNode): string {
131131
const { installLocation } = this.userState;
132-
return `${chalk.bold(node.label)}
133-
${node.message}
132+
return `${node.message}
134133
${node.completed ? `
135134
🏆 Challenge Completed` : node.installed ? `
136135
Open up the challenge in your favorite code editor and follow the instructions in the README:
@@ -303,17 +302,22 @@ Open up the challenge in your favorite code editor and follow the instructions i
303302
} else {
304303
actions["Reset Challenge"] = async () => {
305304
this.clearView();
306-
const targetDir = `${installLocation}/${name}`;
307-
console.log(`Removing ${targetDir}...`);
308-
rmSync(targetDir, { recursive: true, force: true });
309-
console.log(`Installing fresh copy of challenge...`);
310-
await setupChallenge(name, installLocation);
311-
this.globalTree = this.buildTree();
312-
await this.pressEnterToContinue();
313-
this.history.pop(); // Remove the old node from history since it has different actions
314-
// Return to challenge menu
315-
const challengeNode = this.findNode(this.globalTree, name) as TreeNode;
316-
await this.navigate(challengeNode);
305+
const confirmReset = await this.pressEnterToContinue("Are you sure you want to reset this challenge? This will remove the challenge from your local machine and re-install it.", false);
306+
if (!confirmReset) {
307+
await this.goBack();
308+
} else {
309+
const targetDir = `${installLocation}/${name}`;
310+
console.log(`Removing ${targetDir}...`);
311+
rmSync(targetDir, { recursive: true, force: true });
312+
console.log(`Installing fresh copy of challenge...`);
313+
await setupChallenge(name, installLocation);
314+
this.globalTree = this.buildTree();
315+
await this.pressEnterToContinue();
316+
this.history.pop(); // Remove the old node from history since it has different actions
317+
// Return to challenge menu
318+
const challengeNode = this.findNode(this.globalTree, name) as TreeNode;
319+
await this.navigate(challengeNode);
320+
}
317321
};
318322
actions["Submit Completed Challenge"] = async () => {
319323
this.clearView();
@@ -337,13 +341,15 @@ Open up the challenge in your favorite code editor and follow the instructions i
337341
return actions;
338342
};
339343

340-
async pressEnterToContinue(customMessage?: string) {
341-
await confirm({
344+
async pressEnterToContinue(customMessage?: string, defaultAnswer: boolean = true) {
345+
const answer = await confirm({
342346
message: typeof customMessage === "string" ? customMessage : 'Press Enter to continue...',
347+
default: defaultAnswer,
343348
theme: {
344349
prefix: "",
345350
}
346351
});
352+
return answer;
347353
}
348354

349355
private clearView(): void {

0 commit comments

Comments
 (0)