justarandomgeek / vscode-factoriomod-debug

Factorio Mod Tool Kit
Other
97 stars 21 forks source link

Add and use arg parser library for plugin #122

Closed JanSharp closed 1 month ago

JanSharp commented 1 month ago

This PR changes the very basic and bad arg parsing that currently exists with this library: https://github.com/JanSharp/LuaArgParser It also adds warn messages for invalid args, and adds the option for --help which shows an info and a log message the same way.

The only issue with the library is that any and every argument that starts with - is going to be treated as an option. If it isn't one of the valid options then all the args are considered to be invalid, so there's simply no way to have the value for an option start with a -, since the library does not have support for --foo=value.

image

JanSharp commented 1 month ago

I wanted to make this PR before I start actually using the library to get your opinion on it @justarandomgeek . The library isn't the best unfortunately, but it does make it easy to add options and it prints out help messages for free, which is basically all I really want.

justarandomgeek commented 1 month ago

it does look quite easy to use, and the - issue doesn't seem insurmountable if we decided we needed that. you say it "isn't the best" is there something else noteworthy wrong with it? seems okay to me, though i haven't taken the time to read it fully.

JanSharp commented 1 month ago

Yea it really is mostly the - issue. Outside of that it has features we don't need, which are positional arguments, and subsequently the -- arg stopping the arg parser from parsing options and only parsing positional arguments afterwards is also not needed. Not a big deal though tbh. The only other thing that I thought about afterwards was the fact that sumneko now supports multiple plugins to be loaded, however there is only this one list of arguments. At which point the parser should arguably silently ignore unknown options... but that's also not great.

Ultimately the reason why I say it's not the best is because I remembered there being features I thought it needed but I didn't add... however I can only remember the --foo=value feature, or allowing the same option mutliple times as a way to define arrays (which is pretty minor), so I think my memory is just wrong and it's actually better than I had thought.