Browse Source
* nd/command-list: completion: allow to customize the completable command list completion: add and use --list-cmds=alias completion: add and use --list-cmds=nohelpers Move declaration for alias.c to alias.h completion: reduce completable command list completion: let git provide the completable command list command-list.txt: documentation and guide line help: use command-list.txt for the source of guides help: add "-a --verbose" to list all commands with synopsis git: support --list-cmds=list-<category> completion: implement and use --list-cmds=main,others git --list-cmds: collect command list in a string_list git.c: convert --list-* to --list-cmds=* Remove common-cmds.h help: use command-list.h for common command list generate-cmds.sh: export all commands to command-list.h generate-cmds.sh: factor out synopsis extract codemaint

25 changed files with 589 additions and 313 deletions
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
#ifndef __ALIAS_H__ |
||||
#define __ALIAS_H__ |
||||
|
||||
struct string_list; |
||||
|
||||
char *alias_lookup(const char *alias); |
||||
int split_cmdline(char *cmdline, const char ***argv); |
||||
/* Takes a negative value returned by split_cmdline */ |
||||
const char *split_cmdline_strerror(int cmdline_errno); |
||||
void list_aliases(struct string_list *list); |
||||
|
||||
#endif |
@ -1,50 +1,90 @@
@@ -1,50 +1,90 @@
|
||||
#!/bin/sh |
||||
|
||||
echo "/* Automatically generated by generate-cmdlist.sh */ |
||||
struct cmdname_help { |
||||
char name[16]; |
||||
char help[80]; |
||||
unsigned char group; |
||||
}; |
||||
die () { |
||||
echo "$@" >&2 |
||||
exit 1 |
||||
} |
||||
|
||||
command_list () { |
||||
grep -v '^#' "$1" |
||||
} |
||||
|
||||
static const char *common_cmd_groups[] = {" |
||||
|
||||
grps=grps$$.tmp |
||||
match=match$$.tmp |
||||
trap "rm -f '$grps' '$match'" 0 1 2 3 15 |
||||
|
||||
sed -n ' |
||||
1,/^### common groups/b |
||||
/^### command list/q |
||||
/^#/b |
||||
/^[ ]*$/b |
||||
h;s/^[^ ][^ ]*[ ][ ]*\(.*\)/ N_("\1"),/p |
||||
g;s/^\([^ ][^ ]*\)[ ].*/\1/w '$grps' |
||||
' "$1" |
||||
printf '};\n\n' |
||||
|
||||
n=0 |
||||
substnum= |
||||
while read grp |
||||
do |
||||
echo "^git-..*[ ]$grp" |
||||
substnum="$substnum${substnum:+;}s/[ ]$grp/$n/" |
||||
n=$(($n+1)) |
||||
done <"$grps" >"$match" |
||||
|
||||
printf 'static struct cmdname_help common_cmds[] = {\n' |
||||
grep -f "$match" "$1" | |
||||
sed 's/^git-//' | |
||||
sort | |
||||
while read cmd tags |
||||
do |
||||
tag=$(echo "$tags" | sed "$substnum; s/[^0-9]//g") |
||||
get_categories () { |
||||
tr ' ' '\n'| |
||||
grep -v '^$' | |
||||
sort | |
||||
uniq |
||||
} |
||||
|
||||
category_list () { |
||||
command_list "$1" | |
||||
cut -c 40- | |
||||
get_categories |
||||
} |
||||
|
||||
get_synopsis () { |
||||
sed -n ' |
||||
/^NAME/,/git-'"$cmd"'/H |
||||
/^NAME/,/'"$1"'/H |
||||
${ |
||||
x |
||||
s/.*git-'"$cmd"' - \(.*\)/ {"'"$cmd"'", N_("\1"), '$tag'},/ |
||||
s/.*'"$1"' - \(.*\)/N_("\1")/ |
||||
p |
||||
}' "Documentation/git-$cmd.txt" |
||||
done |
||||
echo "};" |
||||
}' "Documentation/$1.txt" |
||||
} |
||||
|
||||
define_categories () { |
||||
echo |
||||
echo "/* Command categories */" |
||||
bit=0 |
||||
category_list "$1" | |
||||
while read cat |
||||
do |
||||
echo "#define CAT_$cat (1UL << $bit)" |
||||
bit=$(($bit+1)) |
||||
done |
||||
test "$bit" -gt 32 && die "Urgh.. too many categories?" |
||||
} |
||||
|
||||
define_category_names () { |
||||
echo |
||||
echo "/* Category names */" |
||||
echo "static const char *category_names[] = {" |
||||
bit=0 |
||||
category_list "$1" | |
||||
while read cat |
||||
do |
||||
echo " \"$cat\", /* (1UL << $bit) */" |
||||
bit=$(($bit+1)) |
||||
done |
||||
echo " NULL" |
||||
echo "};" |
||||
} |
||||
|
||||
print_command_list () { |
||||
echo "static struct cmdname_help command_list[] = {" |
||||
|
||||
command_list "$1" | |
||||
while read cmd rest |
||||
do |
||||
printf " { \"$cmd\", $(get_synopsis $cmd), 0" |
||||
for cat in $(echo "$rest" | get_categories) |
||||
do |
||||
printf " | CAT_$cat" |
||||
done |
||||
echo " }," |
||||
done |
||||
echo "};" |
||||
} |
||||
|
||||
echo "/* Automatically generated by generate-cmdlist.sh */ |
||||
struct cmdname_help { |
||||
const char *name; |
||||
const char *help; |
||||
uint32_t category; |
||||
}; |
||||
" |
||||
define_categories "$1" |
||||
echo |
||||
define_category_names "$1" |
||||
echo |
||||
print_command_list "$1" |
||||
|
Loading…
Reference in new issue