Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse arguments from single string. #98

Closed
AjGodara opened this issue Mar 9, 2021 · 1 comment
Closed

Parse arguments from single string. #98

AjGodara opened this issue Mar 9, 2021 · 1 comment

Comments

@AjGodara
Copy link

AjGodara commented Mar 9, 2021

Hi,
I am trying to use command line style options for a function which is to be called from other functions. Here the entire command will be passed as a single string(not a vector of strings as i see in most of the examples here). Is there a way for me to utilize the args library to extract the options out of that command? Here, some of the options could include quoted filenames with spaces in-between, so a simple space based partition of the original string is too simplistic to work.

@Taywee
Copy link
Owner

Taywee commented Mar 9, 2021

That's out of the scope of this library, unfortunately. If I were to write up an interface for properly splitting up such a formatted string into an array of arguments with string escaping and all, I'd be inclined to package that as a separate library, rather than packaging it in this one anyway.

You could write such a parser simply enough. If your needs are very simple (ie. no need for escapes of any sort, including escaped quotes inside of quoted strings), you could split on your wanted quote character, then split the even parts by whitespace to get your argument list. If your needs are more complex, you're probably better off with a real parser. A naive character-by-character parser would likely be sufficient.

@Taywee Taywee closed this as completed Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants