Skip to content

Commit 189ab71

Browse files
committed
[CODE-70] Added apply complete message with insturctions to source .zshrc or go to a new terminal. Fixed various text bugs with messages missing "". Fixed bug with sudo not working. Fixed plugin name display
1 parent 46c9048 commit 189ab71

9 files changed

Lines changed: 44 additions & 15 deletions

File tree

src/commands/apply/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default class Apply extends BaseCommand {
4646
}
4747

4848
await ApplyOrchestrator.run(planResult);
49+
await this.reporter.displayApplyComplete([]);
4950

5051
process.exit(0);
5152
}

src/plugins/plugin-process.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class PluginProcess {
4444
_process.on('exit', (code) => {
4545
throw new Error(`Plugin ${this.name} exited with code ${code}`);
4646
})
47-
PluginProcess.handleSudoRequests(_process);
47+
PluginProcess.handleSudoRequests(_process, name);
4848

4949
return new PluginProcess(_process);
5050
}
@@ -78,7 +78,7 @@ export class PluginProcess {
7878
return true;
7979
}
8080

81-
private static handleSudoRequests(process: ChildProcess) {
81+
private static handleSudoRequests(process: ChildProcess, pluginName: string) {
8282
// Listen for incoming sudo incoming sudo requests
8383
process.on('message', (message) => {
8484
if (!ipcMessageValidator(message)) {
@@ -88,16 +88,16 @@ export class PluginProcess {
8888
if (message.cmd === MessageCmd.SUDO_REQUEST) {
8989
const { data } = message;
9090
if (!sudoRequestValidator(data)) {
91-
throw new Error(`Invalid sudo request from plugin ${this.name}. ${JSON.stringify(sudoRequestValidator.errors, null, 2)}`);
91+
throw new Error(`Invalid sudo request from plugin ${pluginName}. ${JSON.stringify(sudoRequestValidator.errors, null, 2)}`);
9292
}
9393

94-
ctx.sudoRequested(this.name, data as unknown as SudoRequestData);
94+
ctx.sudoRequested(pluginName, data as unknown as SudoRequestData);
9595
}
9696
})
9797

9898
// Send out sudo granted events
99-
ctx.on(Event.SUDO_REQUEST_GRANTED, (pluginName, data) => {
100-
if (pluginName === this.name) {
99+
ctx.on(Event.SUDO_REQUEST_GRANTED, (_pluginName, data) => {
100+
if (_pluginName === pluginName) {
101101
process.send({
102102
cmd: resultFunctionName(MessageCmd.SUDO_REQUEST),
103103
data

src/plugins/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Plugin {
5252
const { data, status } = await this.process!.sendMessageForResult({ cmd: 'validate', data: { configs: rawConfigs } });
5353

5454
if (status === MessageStatus.ERROR) {
55-
throw new Error(`Initialize error for plugin: "${this.name} \n\n` + data);
55+
throw new Error(`Initialize error for plugin: "${this.name}" \n\n` + data);
5656
}
5757

5858
if (!this.validateValidateResponse(data)) {

src/ui/components/default-component.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function DefaultComponent(props: {
6464

6565
return <Box flexDirection="column">
6666
{
67-
([RenderState.APPLYING, RenderState.GENERATING_PLAN].includes(state)) && progressState && !hideProgress && (
67+
([RenderState.APPLY_COMPLETE, RenderState.APPLYING, RenderState.GENERATING_PLAN].includes(state)) && progressState && !hideProgress && (
6868
<ProgressDisplay progress={progressState}/>
6969
)
7070
}
@@ -84,6 +84,15 @@ export function DefaultComponent(props: {
8484
</Box>
8585
)
8686
}
87+
{
88+
state === RenderState.APPLY_COMPLETE && (
89+
<Box flexDirection="column">
90+
<Text> </Text>
91+
<Text>🎉 Finished applying 🎉</Text>
92+
<Text>Open a new terminal or source '.zshrc' for the new changes to be reflected</Text>
93+
</Box>
94+
)
95+
}
8796
{
8897
showSudoPrompt && (
8998
<Box flexDirection="column">

src/ui/reporters/debug-reporter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ export class DebugReporter implements Reporter {
2626
}
2727

2828
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
29-
console.log(chalk.blue(`Plugin: ${pluginName} requires root access to run command: '${data.command}'`));
29+
console.log(chalk.blue(`Plugin: "${pluginName}" requires root access to run command: "${data.command}"`));
3030
return SudoUtils.runCommand(data.command, data.options, secureMode, pluginName);
3131
}
3232

3333
async promptApplyConfirmation(): Promise<boolean> {
3434
const response = await new Promise((resolve) => {
35-
this.rl.question('Is this okay?\n', (answer) => resolve(answer));
35+
this.rl.question('Is this okay? (only \'yes\' is accepted)\n', (answer) => resolve(answer));
3636
});
3737

3838
return response === 'yes';
@@ -42,6 +42,11 @@ export class DebugReporter implements Reporter {
4242
console.log(JSON.stringify(plan, null, 2));
4343
}
4444

45+
displayApplyComplete(message: string[]): void {
46+
console.log('🎉 Finished applying 🎉');
47+
console.log('Open a new terminal or source \'.zshrc\' for the new changes to be reflected')
48+
}
49+
4550
private getDebug(name: string): Debugger {
4651
if (!this.debuggerCache.has(name)) {
4752
this.debuggerCache.set(name, createDebug(`plugin:${name}`));

src/ui/reporters/default-reporter.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class DefaultReporter implements Reporter {
3737
}
3838

3939
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
40-
console.log(chalk.blue(`Plugin: ${pluginName} requires root access to run command: '${data.command}'`));
40+
console.log(chalk.blue(`Plugin: "${pluginName}" requires root access to run command: "${data.command}"`));
4141

4242
let password;
4343

@@ -84,6 +84,12 @@ export class DefaultReporter implements Reporter {
8484
return continueApply;
8585
}
8686

87+
displayApplyComplete(messages: string[]): Promise<void> | void {
88+
this.renderEmitter.emit(RenderEvent.STATE_TRANSITION, {
89+
nextState: RenderState.APPLY_COMPLETE,
90+
});
91+
}
92+
8793
private log(args: string): void {
8894
this.renderEmitter.emit(RenderEvent.LOG, args);
8995
}

src/ui/reporters/plain-reporter.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@ export class PlainReporter implements Reporter {
1818
}
1919

2020
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
21-
console.log(chalk.blue(`Plugin: ${pluginName} requires root access to run command: '${data.command}'`));
21+
console.log(chalk.blue(`Plugin: "${pluginName}" requires root access to run command: "${data.command}"`));
2222
return SudoUtils.runCommand(data.command, data.options, secureMode, pluginName);
2323
}
2424

2525
async promptApplyConfirmation(): Promise<boolean> {
2626
const response = await new Promise((resolve) => {
27-
this.rl.question('Is this okay?\n', (answer) => resolve(answer));
27+
this.rl.question('Is this okay? (only \'yes\' is accepted)\n', (answer) => resolve(answer));
2828
});
2929

3030
return response === 'yes';
3131
}
3232

3333
displayPlan(plan: PlanResponseData[]): void {
34-
console.log(JSON.stringify(plan));
34+
console.log(JSON.stringify(plan, null, 2));
35+
}
36+
37+
displayApplyComplete(message: string[]): void {
38+
console.log('🎉 Finished applying 🎉');
39+
console.log('Open a new terminal or source \'.zshrc\' for the new changes to be reflected')
3540
}
3641

3742
}

src/ui/reporters/reporter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export enum RenderState { // TODO: instead of having GENERATE_PLAN and APPLYING
2323
DISPLAY_PLAN,
2424
PROMPT_APPLY_CONFIRMATION,
2525
APPLYING,
26+
APPLY_COMPLETE
2627
}
2728

2829
export interface StateTransition {
@@ -34,6 +35,8 @@ export interface DisplayPlanStateTransition extends StateTransition {
3435
}
3536

3637
export interface Reporter {
38+
displayApplyComplete(message: string[]): Promise<void> | void;
39+
3740
displayPlan(plan: PlanResponseData[]): void
3841

3942
promptApplyConfirmation(): Promise<boolean>

src/utils/sudo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function codifySpawn(
6666
const _cmd = password ?
6767
secureMode
6868
? `sudo -k; sudo -SN <<< "${password}" ${cmd}`
69-
: `sudo -S <<< "password" ${cmd}`
69+
: `sudo -S <<< "${password}" ${cmd}`
7070
: secureMode
7171
? `sudo -k; sudo -N ${cmd}`
7272
: `sudo ${cmd}`;

0 commit comments

Comments
 (0)