#!/usr/bin/env bash
# commands/group/rename.sh

function cmd::group::rename::on_load() {
  flag::define --name    value "Current group name" required label:name
  flag::define --new-name value "New group name"   required label:name
}

function cmd::group::rename::run() {
  flag::parse "$@" || return 1
  local name;     name=$(flag::value --name)
  local new_name; new_name=$(flag::value --new-name)
  [[ -z "$name" || -z "$new_name" ]] && \
    log::error "Missing required flags: --name and --new-name" && return 1
  group::require_exists "$name" || return 1
  if group::exists "$new_name"; then
    log::error "Group already exists: ${new_name}"; return 1
  fi
  cmd::group::_rename_impl "$name" "$new_name"
}
