cmd2
cmd2 copied to clipboard
how to save the Settable
I have customized some Settables and want to keep the values of these Settables on next startup. How should I save these Settables? Thanks.
It's entirely up to you how you want to persist settings. The Settable has as an attribute onchange_cb that allows you to provide a callback function when that setting is changed.
On start-up, after the cmd2.Cmd constructor is complete, you can load the values from whatever persistence method you choose and load the values in the settables (cmd2.Cmd.settables)
Here's an example of a cmd2 based application that reads settables from a TOML file. This method loads the settings from a file and applies them: https://github.com/tomcatmanager/tomcatmanager/blob/main/src/tomcatmanager/interactive_tomcat_manager.py#L1625. And here's the documentation that shows how the settings work from a user perspective: https://tomcatmanager.readthedocs.io/en/stable/interactive/configfile.html