Closed saaadel closed 6 years ago
There is work in progress (see #293) on a tokenizer that splits up a single string into an array of command line arguments, which can then be processed with the CommandLine
class as usual.
Can you try using the CommandTokenizer
class in #293 and see if it does what you need? (Feedback very welcome.)
Did this answer your question?
I need two days to check this
Ok, I've reviewed this PR and ran some tests. It works like ArgumentTokenizer class from DrJava project.
Feedback on your implementation:
Conclusion: DrJava's class works better now. Please, fix issues.
PS. anyway, I'm searching for something with escapes in windows notation too (with caret symbol. Example: ^" escaped quote) - in separate method or in the same
also, why you have two methods with separate implementation? what needs?
new CommandTokenizer().parse(str)
new CommandTokenizer().parse(scanner)
I mean, why you not replaced parse(str) with short code:
parse(new Scanner(cmd))
?
Closing the question, temporary imported the ArgumentTokenizer class, but plan to switch your version, when you will publish it in maven with that PR and with fixed issues.
Cool. Thanks for reviewing the CommandTokenizer class!
Sorry to revive the old thread, but was the CommandTokenizer
finally published? Somehow I can't locate it in the latest Maven release.
No, it wasn’t.
Instead, we decided to add two modules, picocli-shell-jline2
and picocli-shell-jline3
, and leverage the tokenizer built in to JLine.
@remkop Thanks!
However, I don't see any relevance of jline to solve the problem of this thread, i.e. parsing the full text command into the arguments. Do I miss something? 😕 It looks jline is about interactive command input only.
Just to clarify my use case: I want to use picocli to parse a raw user command which comes as a single text line. Does picocli provide this, or should I use some external tool to parse it to the list of arguments?
Picocli does not provide functionality to parse a single String into separate command arguments. See also https://github.com/remkop/picocli/issues/242 for more discussion and background.
The reason I mention JLine is that this library does provide it in its DefaultParser
class.
[just question] Can I use picocli to parse single String, not String array? For example, I have system property that contains all args with spaces, quotes and escaped quotes there. How to parse it?