1
# shellcheck shell=sh
2

3
optparser() {
4
  # # shellcheck source=lib/getoptions.sh
5
  # . "$SHELLSPEC_LIB/getoptions.sh"
6
  # # shellcheck source=lib/getoptions_help.sh
7
  # . "$SHELLSPEC_LIB/getoptions_help.sh"
8
  # # shellcheck source=lib/getoptions_abbr.sh
9
  # . "$SHELLSPEC_LIB/getoptions_abbr.sh"
10
  # # shellcheck source=lib/libexec/parser_definition.sh
11
  # . "$SHELLSPEC_LIB/libexec/parser_definition.sh"
12
  # eval "$(getoptions parser_definition "$@")"
13

14
  # shellcheck source=lib/libexec/parser_definition_generated.sh
15 0
  . "$SHELLSPEC_LIB/libexec/parser_definition_generated.sh"
16
}
17

18
multiple() {
19 1
  eval "export $1=\"\${$1}\${$1:+$2}\$OPTARG\""
20
}
21

22
boost() {
23 1
  case $OPTARG in
24 1
    1) export "$1_PROFILER=1" "$1_PROFILER_LIMIT=0" ;;
25 1
    *) export "$1_PROFILER=" "$1_PROFILER_LIMIT=10" ;;
26
  esac
27
}
28

29
check_env_name() {
30 1
  case ${OPTARG%%\=*} in ([!a-zA-Z_]*) return 1; esac
31 1
  case ${OPTARG%%\=*} in (*[!a-zA-Z0-9_]*) return 1; esac
32 1
  return 0
33
}
34

35
set_path() {
36 1
  export "$1=$OPTARG"
37
}
38

39
set_env() {
40 1
  case $OPTARG in
41 1
    *=*) set -- "${OPTARG%%\=*}" "${OPTARG#*\=}" ;;
42
    *)
43 1
      eval "[ \${$OPTARG+x} ] &&:" || return 0
44 1
      eval "set -- \"\$OPTARG\" \"\${$OPTARG}\""
45
  esac
46 1
  export "$1=$2"
47
}
48

49
check_env_file() {
50 1
  case $OPTARG in
51 1
    /* | ./* | ../*) : ;;
52 1
    *) OPTARG="./$OPTARG" ;;
53
  esac
54 1
  [ -f "$OPTARG" ]
55
}
56

57
only_failures() {
58 1
  export "$1_QUICK=1" "$1_REPAIR=1"
59
}
60

61
next_failure() {
62 1
  export "$1_QUICK=1" "$1_REPAIR=1" "$1_FAIL_FAST_COUNT=1" "$1_RANDOM="
63
}
64

65
check_random() {
66 1
  case $OPTARG in
67 1
    none | none:*) return 0 ;;
68 1
    specfiles | specfiles:*) return 0 ;;
69 1
    examples | examples:*) return 0 ;;
70
  esac
71 1
  return 1
72
}
73

74
random() {
75 1
  case $OPTARG in (none | none:*)
76 1
    OPTARG=''
77
  esac
78 1
  case $OPTARG in
79 1
    *:*) export "$1_RANDOM=${OPTARG%%:*}" "$1_SEED=${OPTARG#*:}" ;;
80 1
    *) export "$1_RANDOM=$OPTARG" "$1_SEED=" ;;
81
  esac
82
}
83

84
xtrace() {
85 1
  case $OPTARG in
86 1
    0) export "$1_XTRACE=" "$1_XTRACE_ONLY=" ;;
87 1
    1) export "$1_XTRACE=1" "$1_XTRACE_ONLY" ;;
88 1
    2) export "$1_XTRACE=1" "$1_XTRACE_ONLY=1" ;;
89
  esac
90
}
91

92
is_terminal() { [ -t 1 ]; }
93
detect_color_mode() {
94 1
  export "$1_COLOR="
95 1
  [ "${NO_COLOR:-}" ] && return 0
96 1
  if is_terminal || [ "${FORCE_COLOR:-}" ]; then
97 1
    export "$1_COLOR=1"
98
  fi
99
}
100

101
quiet() {
102 1
  export "$1_SKIP_MESSAGE=quiet" "$1_PENDING_MESSAGE=quiet"
103
}
104

105
mode() {
106 1
  case $OPTARG in
107
    specfiles | examples | examples:id | examples:lineno | debug)
108 1
      export "$1_MODE=list" "$1_LIST=$OPTARG" ;;
109 1
    count) export "$1_MODE=list" "$1_LIST=" ;;
110 1
    *) export "$1_MODE=$OPTARG" "$1_LIST=" ;;
111
  esac
112
}
113

114
check_number() {
115 1
  case $OPTARG in (*[!0-9]*) return 1; esac
116 1
  return 0
117
}
118

119
check_formatter() {
120 1
  case $OPTARG in (*[!a-z0-9_]*) return 1; esac
121 1
  set -- progress documentation tap junit failures
122 1
  while [ $# -gt 0 ]; do
123 1
    case $1 in ($OPTARG*) OPTARG=$1; esac
124 1
    shift
125
  done
126 1
  return 0
127
}
128

129
help() {
130 1
  usage | while IFS= read -r line; do
131 1
    if [ "$1" = "--help" ]; then
132 1
      echo "${line%\ \|\ *}"
133
    else
134 1
      spaces=${line%%[! ]*}
135 1
      [ ${#spaces} -ge 10 ] || echo "$line"
136
    fi
137
  done
138
}
139

140
error_handler() {
141
  # $1: echo or output function
142
  # $2: Default error message
143
  # $3: Error name
144
  # $4: Option
145
  # $5-: Validator name and arguments
146 1
  case $3 in
147 1
    check_number:*) set -- "$1" "Not a number: $4" ;;
148 1
    check_formatter:*) set -- "$1" "Invalid formatter name: $4" ;;
149 1
    check_env_name:*) set -- "$1" "Invalid environment name: $4" ;;
150 1
    check_env_file:*) set -- "$1" "Not found env file: $4" ;;
151
    check_random:*)
152 1
      set -- "$1" "Specify in one of the following formats" "$4"
153 1
      set -- "$1" "$2 (none[:SEED], specfiles[:SEED], examples[:SEED]): $3"
154
  esac
155 1
  "$1" "$2"
156 1
  return 1
157
}
158

159
deprecated() {
160 0
  case $1 in
161
    --keep-tempdir)
162 0
      warn "--keep-tempdir is deprecated. replace with --keep-tmpdir."
163
  esac
164
}

Read our documentation on viewing source code .

Loading