SamuelSchlesinger / commander-cli

A simple library I wrote to allow me to quickly and easily construct command line interfaces.
MIT License
29 stars 2 forks source link

Configuration File Support #47

Open BebeSparkelSparkel opened 1 year ago

BebeSparkelSparkel commented 1 year ago

It seems natural to allow intermixing of command line parameters and configuration file parameters.

I have not figured out a good way of implementing this yet but I have written a crude start. https://github.com/BebeSparkelSparkel/commander-cli/commit/58ccaa7668f37faa46d264097291ae977dafb779?diff=unified#diff-0fdf6337b7344d0659520693ed886d16bcaa1726b984e9a032da849ed05c61e7

One of the problems is that the structure and parsing work already completed to create conf is lost in the merge back to State. One poor solution I have thought of is changing State to something like

type State = [Item]
data Item
  = ItemUnparsed String
  | ItemParsed Dynamic

which allows preparsed data to be passed through.

Do you have any thoughts on how to accomplish this?

SamuelSchlesinger commented 1 year ago

Not sure I agree config files belong in the backtracking way parsing works with commander-cli

BebeSparkelSparkel commented 1 year ago

Something that I have found to be very useful is being able to have cli arguments overpower with config file settings. I do appreciate your non intermixing of config opinion because there is not a good way merging differing structures well.

SamuelSchlesinger commented 1 year ago

I guess the way I'd include a config is by a path parameter or an environment variable, but maybe I'm missing something useful. Is there a good example where this was quite helpful?

BebeSparkelSparkel commented 1 year ago

This isn't a great example but bitcoind allows for this behavior https://manpages.debian.org/testing/bitcoind/bitcoind.1.en.html

The conf file field can be superseded by the cli parameter

SamuelSchlesinger commented 1 year ago

Interesting, yeah I mean if there's a widely used tool that has that behavior I'm open to a patch to support it.

BebeSparkelSparkel commented 1 year ago

I currently do not have a good design for this. Do you have any thoughts on the limited expressiveness of the state? The Parameter Sections #48 could be a solution for nested structures.

SamuelSchlesinger commented 1 year ago

I feel like there's a world where state is modular, I'd have to take a hack at it though.

SamuelSchlesinger commented 1 year ago

Thinking at this again, I feel like configuration files being part of backtracking might be likely to create confusion among newer users.