119625d8cSopenharmony_ci
219625d8cSopenharmony_ciuse builtin;
319625d8cSopenharmony_ciuse str;
419625d8cSopenharmony_ci
519625d8cSopenharmony_ciset edit:completion:arg-completer[my-app] = {|@words|
619625d8cSopenharmony_ci    fn spaces {|n|
719625d8cSopenharmony_ci        builtin:repeat $n ' ' | str:join ''
819625d8cSopenharmony_ci    }
919625d8cSopenharmony_ci    fn cand {|text desc|
1019625d8cSopenharmony_ci        edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
1119625d8cSopenharmony_ci    }
1219625d8cSopenharmony_ci    var command = 'my-app'
1319625d8cSopenharmony_ci    for word $words[1..-1] {
1419625d8cSopenharmony_ci        if (str:has-prefix $word '-') {
1519625d8cSopenharmony_ci            break
1619625d8cSopenharmony_ci        }
1719625d8cSopenharmony_ci        set command = $command';'$word
1819625d8cSopenharmony_ci    }
1919625d8cSopenharmony_ci    var completions = [
2019625d8cSopenharmony_ci        &'my-app'= {
2119625d8cSopenharmony_ci            cand -c 'c'
2219625d8cSopenharmony_ci            cand -v 'v'
2319625d8cSopenharmony_ci            cand -h 'Print help'
2419625d8cSopenharmony_ci            cand --help 'Print help'
2519625d8cSopenharmony_ci            cand test 'Subcommand'
2619625d8cSopenharmony_ci            cand help 'Print this message or the help of the given subcommand(s)'
2719625d8cSopenharmony_ci        }
2819625d8cSopenharmony_ci        &'my-app;test'= {
2919625d8cSopenharmony_ci            cand -d 'd'
3019625d8cSopenharmony_ci            cand -c 'c'
3119625d8cSopenharmony_ci            cand -h 'Print help'
3219625d8cSopenharmony_ci            cand --help 'Print help'
3319625d8cSopenharmony_ci        }
3419625d8cSopenharmony_ci        &'my-app;help'= {
3519625d8cSopenharmony_ci            cand test 'Subcommand'
3619625d8cSopenharmony_ci            cand help 'Print this message or the help of the given subcommand(s)'
3719625d8cSopenharmony_ci        }
3819625d8cSopenharmony_ci        &'my-app;help;test'= {
3919625d8cSopenharmony_ci        }
4019625d8cSopenharmony_ci        &'my-app;help;help'= {
4119625d8cSopenharmony_ci        }
4219625d8cSopenharmony_ci    ]
4319625d8cSopenharmony_ci    $completions[$command]
4419625d8cSopenharmony_ci}
45