Skip to content

Commit

Permalink
feat: broke out reusable command body generation (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaryt authored Aug 15, 2022
1 parent e8790e4 commit 3a4875d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/lib/Components/Commands/exports/Reusable/ReusableCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommandParameterLiteral } from '../../../Parameters/types/CustomParamet
import {
AnyCommandShape,
CommandParameters,
ReusableCommandBodyShape,
ReusableCommandShape,
} from '../../types/Command.types';
import { Command } from '../Command';
Expand Down Expand Up @@ -49,16 +50,20 @@ export class ReusableCommand
}

generate(flatten?: boolean): ReusableCommandShape {
return {
[this.name]: this.generateContents(flatten),
};
}

generateContents(flatten?: boolean): ReusableCommandBodyShape {
const generatedSteps: AnyCommandShape[] = this.steps.map((step) =>
step.generate(flatten),
);

return {
[this.name]: {
parameters: this.parameters?.generate(),
steps: generatedSteps,
description: this.description,
},
parameters: this.parameters?.generate(),
steps: generatedSteps,
description: this.description,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export class ReusedCommand implements Command {
*/
generate(): CommandShape {
return {
[this.name]: { ...this.parameters },
[this.name]: this.generateContents(),
};
}

generateContents(): CommandParameters {
return { ...this.parameters };
}

get generableType(): GenerableType {
return GenerableType.REUSED_COMMAND;
}
Expand Down

0 comments on commit 3a4875d

Please sign in to comment.