cmd2 icon indicating copy to clipboard operation
cmd2 copied to clipboard

how to save the Settable

Open tangc1986 opened this issue 1 year ago • 2 comments

I have customized some Settables and want to keep the values of these Settables on next startup. How should I save these Settables? Thanks.

tangc1986 avatar Feb 21 '24 08:02 tangc1986

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)

anselor avatar Feb 21 '24 16:02 anselor

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

kotfu avatar Feb 21 '24 19:02 kotfu