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

function cmd::group::add::on_load() {
  flag::define --name value "Group name"        required label:name
  flag::define --desc value "Group description" label:desc
}

function cmd::group::add::run() {
  flag::parse "$@" || return 1
  local name; name=$(flag::value --name)
  local desc; desc=$(flag::value --desc)
  [[ -z "$name" ]] && log::error "Missing required flag: --name" && return 1
  if group::exists "$name"; then
    log::error "Group already exists: ${name}"; return 1
  fi
  json::create_group "$(group::path "$name")" "$name" "$desc"
  log::wg_success "Group created: ${name}"
}
