MBulli / SmartCommandlineArgs

A Visual Studio Extension which aims to provide a better UI to manage your command line arguments
GNU General Public License v2.0
99 stars 35 forks source link

Add ENV var support #136

Closed dbgarlisch closed 1 year ago

dbgarlisch commented 2 years ago

Similar to command line args, being able to define and manage and group ENV vars on a per-project basis would be spectacular.

For debugging, I often find myself needing to change env vars at the same time I am changing command line args.

My debugging life would be much simplified and less error prone if I could group them together.

Basically, controlling Arguments, working directory (#98), and environment on a per-project basis would be perfect.

vrubleg commented 1 year ago

As an idea how it could be added to the current interface. All items in the table could have type, by default the type is arg/cmd (it could be displayed on a 16x16 icon before text, like groups of parameters have the icon of folder), but it could be changed to env (where the item should be in format NAME=value or NAME= for empty environment variable) or to dir/cd/wd (where the item is working directory, relative to project directory as VS does by default). Changing type could be done from context menu of a row (maybe it's simpler to implement), or type icon could work as a drop down menu with 3 options.

Working directory should be selected by radio buttons instead of checkboxes. If a group of parameters have a working directory inside, the whole group should use a radio button then (automatic exclusive mode). It can be useful when you have a few sets of parameters for testing (e.g. for different use cases) that should use different working directories.

It's just an idea how it could be integrated into interface without bloating it. The plugin is very convenient and valuable even in current state, support of setting environment variables and working directory would just make it more powerful and cover all possible cases related to testing command line programs.

Irame commented 1 year ago

That's funny I was thinking about the exact same solution for ENV vars.

But I think that the solution for working directory isn't that easy.

My "solution" would be to add a option like "Working Directories" to groups but only one group can have this option set. This group then has exclusive mode enabled and everything inside it is treated as a working directory.

vrubleg commented 1 year ago

Maybe it can be resolved in a simpler way.

It is possible that there are duplicates of ENV variables. It is safe to assume that the last ENV variable with the same name wins. Similar approach could be applied to working directory: the last active one is actually used. Unused duplicates of ENV variables and working directories can be just grayed out in the table.

Irame commented 1 year ago

implemented in e5a6599832a2ff9a30d6fb9bebab90dc0bbad98c

dbgarlisch commented 1 year ago

Thank you!

Irame commented 1 year ago

You're welcome!

I have a question about a feature. I thought about adding the option to change an item from CLA to ENV and back (right now, to create an ENV item, you click the small arrow next to the plus-icon and choose "Add new Environment Variable"). I added this feature but then removed it because I thought it would make the context menu too crowded. But now I think that when you copy and paste text or files, it only makes normal CLAs. Would giving an option to change the item type be a good way to include this function for ENV items without bothering regular users too much? What do you think?

dbgarlisch commented 1 year ago

I am not understanding what you are describing.

Maybe after I have had a chance to use the new env feature, I will be able to give a more informed answer.

Is there a release date for the env feature?

Irame commented 1 year ago

Ok sorry I didn't describe it properly. I think I will add the option anyway and you can let me know what you think.

I think I will release a new version in the next two weeks.

Irame commented 1 year ago

FYI: This is now available in v2.6.0

vrubleg commented 1 year ago

Looks great, but does it support VC++ projects? I tried to test it, but seems like an environment variable is not set, at least getenv returns nullptr instead of the string that I set.

Related to UI, I think that working directory could be handled the same way. Now you can create a few environment variables with the same name, and I guess that the last one should win. The same approach works for Working Directory. As a nicety would be great to grey out lines that are actually not active because of this (and because of current project configuration also), but it is not mandatory. It is already a great tool for development of command line utilities anyway.

Irame commented 1 year ago

Did you enable environment variables in the extension (either in the options panel or the settings dialog)? I disabled it by default so existing projects don't break. I was thinking about a button or something to import existing variables when activating this feature but for now you have to add them manually.

As for the support of VC++ projects. It depends on the debugger used. There is a list at ProjectArguments.cs:159 wich contains all supported debuggers. Missing flavors can be gathered in issue #155 I created for that.

vrubleg commented 1 year ago

Yes, it was turned on. I restarted Visual Studio, and it started to work. Maybe initial setting values were cached somewhere and updated settings weren't taken into account.

dbgarlisch commented 1 year ago

Just updated to the new ENV version.

It.... is.... spectacular!

Having both ENV and command line args in one place will make my debugging life SOOOO much simpler and less error prone.

Thank you again.