// groupNotFound creates generic error messages and exit codes for groupExits, // UserInGroup, and GroupID func groupNotFound(name string) (int, string, error) { // get a nicely formatted list of groups that do exist var existing []string groups, err := usrstatus.Groups() if err != nil { return 1, "", err } for _, group := range groups { existing = append(existing, group.Name) } return errutil.GenericError("Group not found", name, existing) }
func (chk GroupID) Status() (int, string, error) { groups, err := usrstatus.Groups() if err != nil { return 0, "", err } for _, g := range groups { if g.Name == chk.name { if g.ID == chk.id { return errutil.Success() } msg := "Group does not have expected ID" return errutil.GenericError(msg, chk.id, []int{g.ID}) } } return groupNotFound(chk.name) }
func (chk GroupExists) Status() (int, string, error) { // doesGroupExist preforms all the meat of GroupExists doesGroupExist := func(name string) (bool, error) { groups, err := usrstatus.Groups() if err != nil { return false, err } for _, group := range groups { if group.Name == name { return true, nil } } return false, nil } boo, err := doesGroupExist(chk.name) if err != nil { return 1, "", err } else if boo { return errutil.Success() } return groupNotFound(chk.name) }