简体   繁体   中英

Java: Making a simple interactive cli app

I want to make a simple interactive CLI app in Java. The user will type commands like add ... show ... but I am not sure how to set up the commands. Should i have a class for each command or something different?

please take a look at this: https://picocli.info/ . It gives both the library for parsing the cli arguments and also some code examples for structuring.

Apache commons CLI is another Java library for arg parsing.

Typically your cli starts with a single executable program installed on the system, instead of multiple as you indicated (add, show, etc). The executable can take arguments which instruct it to do different things.

So you should have:

  • $ mycli add
  • $ mycli show .

For real examples, check out the CLI from aws and docker .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM