Skip to content
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

proposal: Optional command parameter rework #515

Closed
AndreasHGK opened this issue May 25, 2022 · 1 comment
Closed

proposal: Optional command parameter rework #515

AndreasHGK opened this issue May 25, 2022 · 1 comment
Labels
improvement Improvement of an existing part of the codebase
Milestone

Comments

@AndreasHGK
Copy link
Contributor

There is currently a limitation to how optional commands are done: you cant be sure whether a parameter was provided or that the user just gave the null value as an argument.

This is not unfixable, and I believe something similar to rust's Option<> type might be a way to solve this.
I have already implemented something like this in a library of my own: https://github.com/AndreasHGK/go-interactions and, while not the cleanest implementation, it does seem to work.

A command with an optional parameter would look like this:

type MyCommand struct {
    RequiredParam string
    OptionalParam cmd.Optional[string]
}

func (m MyCommand) Run(...) {
    optionalString, ok := m.OptionalParam.Read()
    alsoOptionalString := m.OptionalParam.ReadOrDefault("this is a default string")
}

Even if this is implemented, the old way of doing commands could technically still be supported but I am not sure if that is such a good idea, and DF is in alpha anyway.

@T14Raptor T14Raptor added feature New feature or request improvement Improvement of an existing part of the codebase labels May 26, 2022
@Sandertv Sandertv added this to the v0.8.0 milestone May 27, 2022
@Sandertv Sandertv removed the feature New feature or request label May 27, 2022
@Sandertv Sandertv modified the milestones: v0.8.0, v0.7.0 May 28, 2022
@Sandertv
Copy link
Member

Closed in 92477eb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement of an existing part of the codebase
Projects
None yet
Development

No branches or pull requests

3 participants