1

Argu is a great library to read program arguments in F#.

But in case of modularization, is it possible somehow to merge different arguments without subcommands? Let's say you have a bunch of command line backends, implemented as modules in one program: a POS cash register, a kitchen order viewer, and a customer database. Each of them may have their service arguments like network address to listen on and a port. And each of them have their own settings, a fixed waiter for the POS or something like that.

My current implementation is

type ServiceArguments =
    | Rest_Service of RestHost: string * RestPort: uint16
    interface IArgParserTemplate with

type PosArguments =
    | [<AltCommandLine("-w")>] [<EqualsAssignmentOrSpaced>] Waiter of uint
    interface IArgParserTemplate with

type ClientArguments =
    | ServiceArguments of service: ServiceArguments 
    | PosArguments of pos: PosArguments
    interface IArgParserTemplate with

I assume there is some kind of interceptor function in Argu, which I could implement. Or should I collect all known arguments for each interface and then provide it to the sub modules? Or is the only way to use subcommands? Feels a bit strange, though.

2
  • 2
    Post examples of the command line arguments you want, not just the code. There are no common arguments in the code you posted. Although it sounds like you're looking for common/global arguments, not merging. Isn't the Subcommands example enough to implement what you want? You can put the common argumens in the Main command, or create a BaseArguments class with the common properties. Commented Dec 20, 2024 at 9:30
  • Well, the argument would be -server localhost -port 4711 for the service part and -waiter 12 -table 8 for the POS part. But the thing is, that they do not know each other. There must not be a global list of arguments. I would even leave the ClientArguments leave out. I assume the subcommands could be a the final solution, but at the end all of them are global arguments. Commented Dec 23, 2024 at 8:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.