ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

Add a way of regenerating the getArgs input, with changes #29

Open ndmitchell opened 9 years ago

ndmitchell commented 9 years ago

From http://code.google.com/p/ndmitchell/issues/detail?id=404:

It would be useful to add the function:

cmdArgsReform :: Mode (CmdArgs a) -> CmdArgs a -> [String]

Given a mode, and a value (presumably returned by cmdArgs or similar, perhaps tweaked slightly) it will give a set of arguments, which when parsed with the given mode, will regenerate the value.

Use case: For servers, it's useful to run them in a mode that continually respawns them if they die. This can usually be done by passing --restart, then running the same program with all but the --restart argument. With cmdArgsReform you parse with CmdArgs, and on seeing the restart just set it to false, and manufacture a new set of equivalent arguments.

Implementation notes: I probably need to add modeReform :: Maybe (a -> [String]) to the mode constructor. During construction we have to manufacture this function, then cmdArgsReform just calls it.

Testing: Testing is rather easy, I just add to the test case driver a test, so it will always get tested that if you run this you get back what you started with.