summaryrefslogtreecommitdiffstats
path: root/sq/make-usage.sh
blob: 7bcbfcf2219f970c0783adf7b129764d9ba2c28d (plain)
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
#!/bin/sh

tool=$1

quote() {
    sed 's@^@//! @' | sed 's/ $//'
}

begin_code() {
    printf '```text\n'
}

end_code() {
    printf '```\n'
}

dump_help() { # subcommand, indentation
    if [ -z "$1" ]
    then
	printf "\n# Usage\n\n"
        set "" "#"
    else
	printf "\n$2 Subcommand$1\n\n"
    fi

    help="`$tool $1 --help`"

    begin_code
    printf "$help\n" | tail -n +2
    end_code

    if echo $help | fgrep -q SUBCOMMANDS
    then
        printf "$help\n" |
            sed -n '/^SUBCOMMANDS:/,$p' |
	    tail -n+2 |
	    grep '^    [^ ]' |
	    while read subcommand desc
	    do
	        if [ "$subcommand" = help ]; then
		    continue
	        fi

                dump_help "$1 $subcommand" "#$2"
	    done
    fi
}

(
    printf "A command-line frontend for Sequoia.\n"
    dump_help
) | quote

printf '\ninclude!("'"$(basename $tool)"'.rs");\n'