Module utils

Module utils 

Source
Expand description

§mcp-sync utilities

Common helper functions for file operations, JSON/TOML manipulation, and path resolution.

Functions§

backup
Creates a backup copy of a file with a timestamped extension.
ensure_parent
Ensures that the parent directory of path exists.
find_git_root
Finds the git repository root by traversing up from start. Returns start if no .git directory is found.
home
Returns the user’s home directory.
json_get_obj_mut
Gets or creates a nested object at key.
json_obj_mut
Returns a mutable reference to the JSON object, or an error if not an object.
log_verbose
Prints a message to stderr if verbose is true.
now_stamp
Generates a timestamp string in YYYYMMDD-HHMMSS format.
read_json_file
Reads a JSON file, returning an empty object if the file doesn’t exist.
write_json_file
Writes a JSON value to a file with pretty-printing. Creates a backup before writing.