-
-
Notifications
You must be signed in to change notification settings - Fork 19
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 bonzai.Persistence and Persister with CmdCompletion #275
Comments
See PR #276 for ongoing development of this addition. |
I saw the PR, even though you'll have the interface and package level variable for the To set the We can't have the default implementation in bonzai because that pulls in a bunch of dependencies and also you can't use the default implementation (from bonzai) in vars because that will cause a circular dependency. |
The problem is Var.Persist. People expect it to automatically persist when set and Cmd.Set is called. The alternative is to call both Set and also something that implements persistence that is not necessarily consistent for everything in the binary. This seems like way more code than just an func main() {
bonzai.Persistence = vars.Driver
foo.Cmd.Run()
} Or maybe a bit of syntactical sugar: func main() {
foo.Cmd.WithPersistence(vars.Driver).Run()
} The Thoughts? |
Another thing is that There's another implicit design question here. Should we mandate declaration of any and all variables used in Vars now? This seems reasonable now that we have a comprehensive way of handling them. It would mean that bonzai command creators follow the same convention for such things that can be relied upon. A command that uses a variable from some other external source then becomes less than best practice unless there is data that must live outside of the Vars space. Opening external application configuration files and such is probably one solid example of this. I do wish we could tackle the abstraction of conventional configuration with standardization on the yq/jq dialect so that I can port certain applications into a universal collection of configuration files. But that is another project. I had that before. Cobra has Viper to attempt this, but it has not been adopted at all, probably because it is lacking the yq/jq dialect. We could specify a |
Also, what about Var.Export or Var.Scope? Now that all declared Cmd.Vars are cached privately, we can block their retrieval in Get/Set to different scopes:
This actually addresses a concern about security that I had before. A branch can be grafted in from an unknown source and even after compilation cannot mess with another Cmds declared Vars if the Cmd author does not want. |
I like the scope idea, that is something you cannot have with package level variables. |
The scope thing also allows us to automatically document Vars based on scope and inheritance stuff. |
I get your point about having to call both the Set(Cmd and vars.Driver) methods. That becomes inevitable. Also, I already thought that Cmd.Vars will now be the "idiomatic" way of handling variables for Cmds. |
Are we going to allow separate persistence drivers per Cmd? You example of |
Allowing that would also require us to have good defaults. If it's not set in all node Cmds of a tree then should it assume the Driver of the parent Cmd? |
By moving the vars.Driver interface definition and adding Complete method into bonzai itself the Set/Get methods can do the work of
var
without requiring the var command to be imported.The text was updated successfully, but these errors were encountered: