-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the scenario wiki!
Each time when we write the CLI application on Java, we have to answer the following questions and then implement the corresponding logic:
- design the menu system:
- which menu should be displayed first?
- which items (choices) should each menu contain?
- which menu should be displayed when user chooses the action or types some text?
- how to prevent the user from typing incorrect value?
- how to call the needed business logic when some action is chosen?
- how to be sure that menu won't fall into never-ending cycle (user won't be able to exit the app)?
... and many others.
It leads to nested if or switch statements, input control classes and other boilerplate code.
The main purpose of the scenario library is to delegate all the CLI menu handling to it, so it will act as a service.
Add the following dependency to your project's pom.xml:
⚠️ WARNING! The release version is not published yet and will be ready when this wiki page is complete.
<dependency>
<groupId>com.github.prifiz</groupId>
<artifactId>scenario</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Okay, you've just added the needed dependency to your project. What's next?
It's time to forget that you're developer and start designing the menu.
It is really easy. You can even ask someone without any programming skills to configure it. The only required thing to know here is YAML syntax.
Now let's create a simple menu configuration:
- Create an empty yaml-file with any name you want, e.g. myfirstmenu.yml
- The root element should be "menuSystem:".
- Create a menu by specifying its name and text.
The name should be unique for referencing this menu by the others, the text value will be displayed in your command line app.
The simplest menu configuration will look like this:
menuSystem:
# Home Menu
- name: "home"
text: |
Welcome to my awesome app.
It was quite easy to configure it!
This is still not actually a menu because it doesn't provide any options to choose. Let's add a couple.
menuSystem:
# Home Menu
- name: "home"
text: |
Welcome to my awesome app.
It was quite easy to configure it!
items:
- name: "option1"
text: "Option One"
- name: "option2"
text: "Option Two"
What happened here:
- our menu will display the welcome text specified in "text" attribute,
- next, the two options will be displayed:
- Option One
- Option Two
But... it is still not a menu.