#!/usr/bin/env bash

set -euo pipefail

if [[ $1 == "list" ]]; then
  LOCKFILE=${NETWORKCTL_MOCK_LOCK_FILE:-"/mock/config/networkctl-list.lock"}
  CONFIG_FILE=${NETWORKCTL_MOCK_LIST_FILE:-"/mock/config/networkctl-list.json"}
  flock "$LOCKFILE" -c "cat $CONFIG_FILE"
else
  # pass through other arguments to real networkctl. implement mocks as needed
  /usr/bin/networkctl "$@"
fi
