Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 742 Bytes

README.md

File metadata and controls

31 lines (23 loc) · 742 Bytes

java-commands

It's a command parser written in java. It takes a command string and return a command object. I know I could just use regex and do it 10 times faster but I wanted to do it manually and do some TDD.

Usage

create a command class

public class PrintCommand extends Command {
    
    @Override
    public void exec() {
        System.out.println(this.params.get("s"));
    }
}

setup commands repository

ICommandsRepository commandsRepository = new CommandsRepository();
commandsRepository.addCommand("print", PrintCommand.class);

parse and execute command

ICommand command = CommandParser.getInstance().parse("print -s \"string to be printed\"", commandsRepository);
command.exec();