I use typescript because it allows me to do a well organized code and apply certain patterns that are useful for the problem.
Next command runs the software with the default test string saved in 'src/examles/basic.txt'
npm install
or yarn install
npx ts-node cli.ts
But you can also pass any path file to the script and it will run it for example:
npx ts-node cli.ts './src/examples/test.txt'
npm run test
or yarn test
I split the problem in 2 parts
- the text to command executable structure
- I created a class called TextToCommandConverter in charge of parse the text and convert to a Command (An object with a statement and params of the statement) that will be running for the CommandRunner class.
- The action statements
- I created an interface called Statement that will be implemented for each tipe of statement (Create, delete, move, list), in this way in the future we will be able to add more instructions conserving the same structure or replace a command implementetion just implementing the same interface.