File: dpll

package info (click to toggle)
iproute2 6.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,380 kB
  • sloc: ansic: 127,486; sh: 1,363; cpp: 946; makefile: 720; yacc: 421; lex: 145; python: 43
file content (316 lines) | stat: -rw-r--r-- 9,822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# bash completion for dpll(8)                             -*- shell-script -*-

# Get all the optional commands for dpll
_dpll_get_optional_commands()
{
    local object=$1; shift

    local filter_options=""
    local options="$(dpll $object help 2>&1 \
        | command sed -n -e "s/^.*dpll $object //p" \
        | cut -d " " -f 1)"

    # Remove duplicate options from "dpll $OBJECT help" command
    local opt
    for opt in $options; do
        if [[ $filter_options =~ $opt ]]; then
            continue
        else
            filter_options="$filter_options $opt"
        fi
    done

    echo $filter_options
}

# Complete based on given word
_dpll_direct_complete()
{
    local device_id pin_id value

    case $1 in
        device_id)
            value=$(dpll -j device show 2>/dev/null \
                    | jq '.device[].id' 2>/dev/null)
            ;;
        pin_id)
            value=$(dpll -j pin show 2>/dev/null \
                    | jq '.pin[].id' 2>/dev/null)
            ;;
        module_name)
            value=$(dpll -j device show 2>/dev/null \
                    | jq -r '.device[]."module-name"' 2>/dev/null \
                    | sort -u)
            ;;
    esac

    echo $value
}

# Handle device subcommands
_dpll_device()
{
    local command=$1

    case $command in
        show)
            case $prev in
                id)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "id" -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
        set)
            case $prev in
                id)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                phase-offset-monitor)
                    COMPREPLY=( $( compgen -W "enable disable true false 0 1" -- "$cur" ) )
                    return 0
                    ;;
                phase-offset-avg-factor)
                    # numeric value, no completion
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "id phase-offset-monitor \
                        phase-offset-avg-factor" -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
        id-get)
            case $prev in
                module-name)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete module_name)" -- "$cur" ) )
                    return 0
                    ;;
                clock-id)
                    # numeric value, no completion
                    return 0
                    ;;
                type)
                    COMPREPLY=( $( compgen -W "pps eec" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "module-name clock-id type" \
                        -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
    esac
}

# Handle pin subcommands
_dpll_pin()
{
    local command=$1

    case $command in
        show)
            case $prev in
                id)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete pin_id)" -- "$cur" ) )
                    return 0
                    ;;
                device)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "id device" -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
        set)
            case $prev in
                id|parent-device)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete device_id)" -- "$cur" ) )
                    return 0
                    ;;
                parent-pin|reference-sync)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete pin_id)" -- "$cur" ) )
                    return 0
                    ;;
                frequency|phase-adjust|esync-frequency|prio)
                    # numeric value, no completion
                    return 0
                    ;;
                direction)
                    COMPREPLY=( $( compgen -W "input output" -- "$cur" ) )
                    return 0
                    ;;
                state)
                    COMPREPLY=( $( compgen -W \
                        "connected disconnected selectable" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    # Check if we are in nested context (after parent-device/parent-pin/reference-sync)
                    local i nested_keyword=""
                    for (( i=cword-1; i>0; i-- )); do
                        case "${words[i]}" in
                            parent-device)
                                nested_keyword="parent-device"
                                break
                                ;;
                            parent-pin|reference-sync)
                                nested_keyword="parent-pin"
                                break
                                ;;
                            id|frequency|phase-adjust|esync-frequency)
                                # Hit a top-level keyword, not in nested context
                                break
                                ;;
                        esac
                    done

                    if [[ "$nested_keyword" == "parent-device" ]]; then
                        COMPREPLY=( $( compgen -W "direction prio state" -- "$cur" ) )
                    elif [[ "$nested_keyword" == "parent-pin" ]]; then
                        COMPREPLY=( $( compgen -W "state" -- "$cur" ) )
                    else
                        COMPREPLY=( $( compgen -W "id frequency phase-adjust \
                            esync-frequency parent-device parent-pin reference-sync" \
                            -- "$cur" ) )
                    fi
                    return 0
                    ;;
            esac
            ;;
        id-get)
            case $prev in
                module-name)
                    COMPREPLY=( $( compgen -W \
                        "$(_dpll_direct_complete module_name)" -- "$cur" ) )
                    return 0
                    ;;
                clock-id)
                    # numeric value, no completion
                    return 0
                    ;;
                board-label|panel-label|package-label)
                    # string value, no completion
                    return 0
                    ;;
                type)
                    COMPREPLY=( $( compgen -W "mux ext synce-eth-port \
                        int-oscillator gnss" -- "$cur" ) )
                    return 0
                    ;;
                *)
                    COMPREPLY=( $( compgen -W "module-name clock-id \
                        board-label panel-label package-label type" \
                        -- "$cur" ) )
                    return 0
                    ;;
            esac
            ;;
    esac
}

# Handle monitor subcommand
_dpll_monitor()
{
    # monitor has no additional arguments
    return 0
}

# Complete any dpll command
_dpll()
{
    local cur prev words cword
    local opt='--Version --json --pretty'
    local objects="device pin monitor"

    _init_completion || return
    # Gets the word-to-complete without considering the colon as word breaks
    _get_comp_words_by_ref -n : cur prev words cword

    if [[ $cword -eq 1 ]]; then
        case $cur in
            -*)
                COMPREPLY=( $( compgen -W "$opt" -- "$cur" ) )
                return 0
                ;;
            *)
                COMPREPLY=( $( compgen -W "$objects help" -- "$cur" ) )
                return 0
                ;;
        esac
    fi

    # Deal with options
    if [[ $prev == -* ]]; then
        case $prev in
            -V|--Version)
                return 0
                ;;
            -j|--json)
                COMPREPLY=( $( compgen -W "--pretty $objects" -- "$cur" ) )
                return 0
                ;;
            *)
                COMPREPLY=( $( compgen -W "$objects" -- "$cur" ) )
                return 0
                ;;
        esac
    fi

    # Remove all options so completions don't have to deal with them.
    local i
    for (( i=1; i < ${#words[@]}; )); do
        if [[ ${words[i]::1} == - ]]; then
            words=( "${words[@]:0:i}" "${words[@]:i+1}" )
            [[ $i -le $cword ]] && cword=$(( cword - 1 ))
        else
            i=$(( ++i ))
        fi
    done

    local object=${words[1]}
    local command=${words[2]}
    local pprev=${words[cword - 2]}
    local prev=${words[cword - 1]}

    case $object in
        device|pin|monitor)
            if [[ $cword -eq 2 ]]; then
                COMPREPLY=( $( compgen -W "help" -- "$cur") )
                if [[ $object != "monitor" ]]; then
                    COMPREPLY+=( $( compgen -W \
                        "$(_dpll_get_optional_commands $object)" -- "$cur" ) )
                fi
            else
                "_dpll_$object" $command
            fi
            ;;
        help)
            return 0
            ;;
        *)
            COMPREPLY=( $( compgen -W "$objects help" -- "$cur" ) )
            ;;
    esac

} &&
complete -F _dpll dpll

# ex: ts=4 sw=4 et filetype=sh