pub fn add(
ctx: &Context,
req: AddRequest,
) -> Result<Outcome<PantryContents>, CoreError>Expand description
Add an item to the pantry and write it back.
The section is created if the file has no such section, and the file itself
is created if there is none — under <base_path>/config/pantry.conf, which
is where Context::discover looks first. That is the one case where this
crate invents a path rather than being told one.
Returns the pantry as it now stands on disk, so a caller need not read it back, together with any warnings from parsing what was there before.
Only the entry asked for is touched; see what a write touches.
§Errors
CoreError::ReadOnlyConfigif the context carries the pantry inline. There is nowhere to write it, and inventing a path would put an editor’s unsaved buffer on someone’s disk.CoreError::PantryEditif the section already holds an item of that name, compared exactly. Nothing is written;updateis how an item is changed.CoreError::Configif the existing file cannot be parsed at all, andCoreError::Ioif it cannot be read or the new one cannot be written.