blob: 53b237d15f7ce84caf773042087a424508b4cbdc [file] [log] [blame]
Joey Armstrongcc24b3c2024-03-22 11:12:23 -04001#!/bin/bash
2# -----------------------------------------------------------------------
3# Copyright 2024 Open Networking Foundation Contributors
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# SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19## --------------------------------------------------------------------
20## Intent:
21## --------------------------------------------------------------------
22
23## --------------------------------------------------------------------
24## --------------------------------------------------------------------
25function help_read()
26{
27 local -n ref=$1; shift
28 local path="$1"; shift
29
30 readarray text < <(grep -v -e '^#' "$path")
31 ref+=("${text[@]}")
32
33 return
34}
35
36## --------------------------------------------------------------------
37## --------------------------------------------------------------------
38function help_switch_show()
39{
40 local -a buffer=()
41
42 local helpwith
43 for helpwith in "$@"; do
44 local path="$pgm_help/${helpwith}.switches"
45 if [[ ! -e "$path" ]]; then
46 readarray fyls < <(find "$pgm_help" -name '*.switches')
47 echo "--usage-${helpwith} does not exist"
48 echo "Try one of:"
49 printf " %s\n" "${fyls[@]}"
50 error "OUTA HERE"
51 fi
52 help_read buffer "$path"
53 done
54
55 printf '%s' "${buffer[@]}"
56 return
57}
58
59## --------------------------------------------------------------------
60## --------------------------------------------------------------------
61function help_usage_show()
62{
63 local -a buffer=()
64
65 local helpwith
66 for helpwith in "$@"; do
67 local path="$pgm_help/${helpwith}.usage"
68 if [[ ! -e "$path" ]]; then
69 readarray fyls < <(find "$pgm_help" -name '*.usage')
70 echo "--usage-${helpwith} does not exist"
71 echo "Try one of:"
72 printf " %s\n" "${fyls[@]}"
73 error "OUTA HERE"
74 fi
75 help_read buffer "$path"
76 done
77
78 printf '%s' "${buffer[@]}"
79 return
80}
81
82## --------------------------------------------------------------------
83## --------------------------------------------------------------------
84function help_with()
85{
86 help_switch_show "$@"
87 help_usage_show "$@"
88}
89
90# [EOF]