anote
1import { Keywords } from "../flows/Keywords";2import { Command } from "./Command";3import MessageStore from "../service/MessageStore";4import Saver from "../service/Saver";5
6export class Add extends Command {7messageNumber = 5;8
9async execute(): Promise<string> {10if(!this.isValid(Keywords.ADD)) return '[ADD] Not valid command.';11const tail: string = this.getTail();12
13if(tail === '/') {14const input: string = MessageStore.getPreviousValue();15return await new Saver().appendLine("default.txt", input);16}17
18if(this.isValidMessageNumber(tail))19return await new Saver().appendLine("default.txt", MessageStore.getPreviousValue(tail as unknown as number));20
21return '[ADD] Index out of range';22}23
24private isValidMessageNumber(tail: string): boolean {25let flag: boolean = false;26for(let i=0; i<this.messageNumber; i++){27if(tail === i.toString())28flag = true;29}30return flag;31}32}
33