- adds functions - util_create_state - util_read_state - util_write_state - util_delete_state for state management API. see docs/about_states.md for details. - moves functions from _reve.sh to _reve_utils.sh to prevent circular imports.
1.4 KiB
1.4 KiB
reve docs
"about states", revision 1 yigid balaban <fyb@fybx.dev>
about states
different from configuration files, some information is temporary, and "local" to current runtime. some utilities, for example, may need a way to store and access variables. for that reason reve exposes 4 functions to work with states that can be temporary or permanent.
for this reason, states can be created/updated, deleted or read using reve.
reve's API for states
Functions for working with states are defined in _reve.sh
:
util_create_state {type} {key} [value]
: Creates the state file.{type}
can betmp
for temporary orprs
for persistent.util_read_state {key}
: Returns the value read from file addressed by key. Will return1
if an error occurs.util_write_state {key} {value}
: Writes the value to file addressed by key. Will overwrite without warning.util_delete_state {key}
: Deletes the file addressed by key. Will delete the containing folder, if the folder is empty.
underlying implementation
- the
key
s are dot-delimited folders, subfolders and files. The last element of the key is assumed to be the file name. - trying to read, write or delete a file that is not created will return an error.
- as a result of the rule above, writing a new state is not possible, you have to create it with an explicit type first.
- temporary states will be cleaned when the appropriate call is made (
reve state clean
)