#!/bin/bash
# @description reload dynamic groups
# @man By default, dynamic groups are evaluated every 5 minutes.
# @man This command triggers a reload of all dynamic groups.
# @man +
# @man *Options*:
# @man +
# @man *-i*: run the agent in information mode, displays all executed commands
# @man +
# @man *-c*: run the agent without color output

. "${BASEDIR}/../lib/common.sh"
. "${BASEDIR}/../lib/api_call.sh"

DISPLAY_COMMAND=false

while getopts "iIvdc" opt; do
  case $opt in
    i|I|v|d)
      DISPLAY_COMMAND=true
      ;;
    c)
      clear_colors
      ;;
  esac
done

action="reload groups"
curl_opt="--header @/var/rudder/run/api-token-header --request POST"
expected='{"action":"reloadGroups","result":"success","data":{"groups":"Started"}}'

checked_api_call "http://127.0.0.1:8080/rudder/api/latest/system/reload/groups" "reload groups" "${DISPLAY_COMMAND}" "${expected}" "${curl_opt}"

