-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add automatic --wizard command that generates menus and prompts #24
Comments
Heya, I'd like to give this a go! |
@ioreskovic This one will be great fun! There are a few steps:
You might find a person or two to pair with on the Discord (if you like). In any case, please reach out if you run into any issues or have any questions! |
@jdegoes I managed to get it to work*, but with shortcuts, and the code is ugly, and I would like to have some time to do it properly. |
@ioreskovic Yes, it's fine to work on after the hackathon. Let me know if you need any help and be sure to fill out the form to claim your t-shirt! |
@jdegoes I was finally able to pick this up, and I have some questions/issues about how Let's take a subset of
Then, using recursive encoding, it looks like this:
Now, let's take a look at type final case class GitModel(version: Boolean)
case object GitStashModel
final case class GitStashPushModel(force: Boolean)
case object GitStashClearModel
final case class GitPushModel(repo: Option[String])
val git: Command[((GitModel, Unit), (Product, Serializable))] =
Command("git", Options.bool("version", true).as(GitModel), Args.Empty).subcommands(
Command("stash", Options.Empty.map(_ => GitStashModel), Args.Empty)
.subcommands(
Command("push", Options.bool("force", ifPresent = true).as(GitStashPushModel), Args.file("files", Exists.Yes).repeat1),
Command("clear", Options.Empty.map(_ => GitStashClearModel), Args.Empty)
),
Command("push", Options.text("repo").optional("Use different repository").as(GitPushModel), Args.file("files", Exists.Yes).repeat1)
) As we can see here, inferred type is def run(args: List[String]): ZIO[R with Console, Nothing, ExitCode] =
(for {
builtInValidationResult <- command.parseBuiltIn(args, config)
(remainingArgs, builtIn) = builtInValidationResult
_ <- handleBuiltIn(args, builtIn)
validationResult <- command.parse(remainingArgs, config)
} yield validationResult)
.foldM(printDocs, success => execute(success._2))
.exitCode Since wizard is a built-in, it should be handled by My initial idea was to either return But, since that model differs (nested commands may have different models than the top one) from the one Another possible approach would be to have I don't have much experience with recursion schemes, but this smells a bit like it to me, since we have a recursive data structure, which we want to be able to traverse independently of performing specific operations on it's data. However, as I mentioned earlier, the types are giving me a problem, since they do not need to be a part of ADT (or an sealed trait GitCommand
final case class Git(...) extends GitCommand
case object GitStash extends GitCommand
final case class GitStashPush(...) extends GitCommand
...
val command: Command[ArgsAndOptsADT] = ...
val result = command.execute {
case Git(version: Boolean) => ...
case GitStash => ...
case GitStashPush(force: Boolean, files: List[Path]) => ...
...
} but I am not sure how to do it. Any thoughts? |
I think you should not care about the types at all, and simply generate a Note that in a real application, when you use |
We could do a pair programming session for 30 minutes, would that help? |
I would love to, but my timetable is packed until Wednesday. |
Yes, sounds good!
|
/bounty $500 Solution must create very user-friendly menus, and must, after execution, print out the command-line args necessary to re-create that execution. |
|
@jorge-vasquez-2301 If you are interested in finishing this ticket (with the menus, prompts and other deluxe features), feel free to /attempt #24 |
/attempt #24 |
1 similar comment
/attempt #24 |
@pablf: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏 |
💡 @pablf submitted a pull request that claims the bounty. You can visit your org dashboard to reward. |
🎉🎈 @pablf has been awarded $500! 🎈🎊 |
The structure of
Command
permits an interactive mode that generates menus and prompts, e.g.:This ticket is to prototype such a wizard mode, which will walk the user through providing arguments and options using interactive menu prompts.
The text was updated successfully, but these errors were encountered: