bkirwi / decline

A composable command-line parser for Scala.

Home Page:http://monovore.com/decline/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supporting User Input

sinanspd opened this issue · comments

Any thoughts on adding support for user input?

I understand the downside that is, the library will likely have to come with cats-effect by default, instead of being optional (unless this also was a separate module).

But I think it would be vital to enable complex tooling and allow the user to build complex flows.

A very simple example would be

$ decline-clt  diff-push-merge 
     username: ....
     password: ...

    Success!

Furthermore, it would enable something like this ticket => #171

To be turned into

$ decline-clt generate-file
    Enter File Name: ...
    Choose file type:
        [.] Class
        [.] Trait
        [.] Object

It is pretty easy to read single line input with cats-effect but I was thinking about more interactive options (checkboxes and list options, see attachement), in a composable manner.

clt

Something along the lines of

sealed trait UserInput[A]
case class SingleLineInput[A](name: String, message: String) extends UserInput[A]
case class ListInput[A](name: String, message: String, choice: List[String]) extends UserInput[A]
case class CheckBoxInput[A](name: String, message: String, choice: List[String]) extends UserInput[A]

where A is a refined type for validation

We then have a few options to define a flow. I.e. a list of UserInput and saying something along the lines of following would execute the input questions in order and return the result

Opts.flow(value: List[String]).mapN{ (answer1, answer2, answer3, ...) => ...}

You could pass that in a subcommand

Command(
        name = "questions",
        header = "Ask User Some Random Questions"
    ) {
       Opts.flow(value: List[String])
    }

Just some quick thinking.. Various ways to model this, even potentially to allow nested dynamic Flows.

Frankly, I don't know what the goals of this library was when you created it but I feel like something like this would fit well.

I don't think this benefits that much from being combined with the UNIXy command-line parsing stuff, and historically we've tried to keep decline pretty lean, so I think this is probably a no. A nice idea for another library though!