...

Text file src/k8s.io/utils/hack/lib/util.sh

Documentation: k8s.io/utils/hack/lib

     1#!/usr/bin/env bash
     2
     3# Copyright 2014 The Kubernetes Authors.
     4#
     5# Licensed under the Apache License, Version 2.0 (the "License");
     6# you may not use this file except in compliance with the License.
     7# You may obtain a copy of the License at
     8#
     9#     http://www.apache.org/licenses/LICENSE-2.0
    10#
    11# Unless required by applicable law or agreed to in writing, software
    12# distributed under the License is distributed on an "AS IS" BASIS,
    13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14# See the License for the specific language governing permissions and
    15# limitations under the License.
    16
    17# arguments: target, item1, item2, item3, ...
    18# returns 0 if target is in the given items, 1 otherwise.
    19kube::util::array_contains() {
    20  local search="$1"
    21  local element
    22  shift
    23  for element; do
    24    if [[ "${element}" == "${search}" ]]; then
    25      return 0
    26     fi
    27  done
    28  return 1
    29}
    30
    31# kube::util::check-file-in-alphabetical-order <file>
    32# Check that the file is in alphabetical order
    33#
    34function kube::util::check-file-in-alphabetical-order {
    35  local failure_file="$1"
    36  if ! diff -u "${failure_file}" <(LC_ALL=C sort "${failure_file}"); then
    37    {
    38      echo
    39      echo "${failure_file} is not in alphabetical order. Please sort it:"
    40      echo
    41      echo "  LC_ALL=C sort -o ${failure_file} ${failure_file}"
    42      echo
    43    } >&2
    44    false
    45  fi
    46}

View as plain text