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

how to save the Settable #1295

Open
tangc1986 opened this issue Feb 21, 2024 · 2 comments
Open

how to save the Settable #1295

tangc1986 opened this issue Feb 21, 2024 · 2 comments

Comments

@tangc1986
Copy link

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

@anselor
Copy link
Contributor

anselor commented Feb 21, 2024

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)

@kotfu
Copy link
Member

kotfu commented Feb 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants