Hi. Is there a library for parsing command-line op...
# getting-started
t
Hi. Is there a library for parsing command-line options?
k
o
j
I would suggest Clikt over kotlinx-cli, it seems kotlinx-cli is not really active, while Clikt has lots of features
k
I haven't found a CLI library that I'm 100% satisfied with. For example, both of the above will exit the JVM if they receive a "help" command, but sometimes this is not desirable as you might have an application in which you can have multiple command-line sessions, and you don't want such a session to be able to end the application.
j
I'm not sure I understand what you mean. If you have several command line sessions interacting with the same JVM, then it's rather a model with a daemon + a separate CLI process, so the help command would still exit the process of the CLI itself
k
Ok, I understand what you mean. These CLI libraries assume that the command line is what you type at the OS shell level (e.g. in Bash). But what if you want your application to interpret command lines typed inside the application (e.g. how the ftp command works after you type just "ftp" and then you can interact with it in the command line). I expect you should be able to read a line, split it into words, and pass those words to the CLI library. But with the above two, it will break if you type
command --help
.
j
Ah I see what you mean now. I have never needed such a thing, but I get that it's a use case that may happen. I guess there just little demand for that. Such use cases also don't need OS-specific CLI features like generating completion scripts, so maybe it's enough to create your own parser in that case
I'm pretty sure there is a way to customize the help command though. So you might be able to use Clikt for parsing anyway
t
Thank you