]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/cmd-list.perl
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / Documentation / cmd-list.perl
CommitLineData
d7907392
JH
1#!/usr/bin/perl -w
2
3use File::Compare qw(compare);
72fe6a59
JH
4
5sub format_one {
0bf15e74
JH
6 my ($out, $nameattr) = @_;
7 my ($name, $attr) = @$nameattr;
72fe6a59 8 my ($state, $description);
f442f28a 9 my $mansection;
d7907392 10 $state = 0;
72fe6a59
JH
11 open I, '<', "$name.txt" or die "No such file $name.txt";
12 while (<I>) {
f442f28a
PB
13 if (/^git[a-z0-9-]*\(([0-9])\)$/) {
14 $mansection = $1;
15 next;
16 }
72fe6a59
JH
17 if (/^NAME$/) {
18 $state = 1;
19 next;
20 }
21 if ($state == 1 && /^----$/) {
22 $state = 2;
23 next;
24 }
25 next if ($state != 2);
26 chomp;
27 $description = $_;
28 last;
29 }
30 close I;
31 if (!defined $description) {
32 die "No description found in $name.txt";
33 }
34 if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
f442f28a 35 print $out "linkgit:$name\[$mansection\]::\n\t";
79d30668
JH
36 if ($attr =~ / deprecated /) {
37 print $out "(deprecated) ";
0bf15e74
JH
38 }
39 print $out "$text.\n\n";
72fe6a59
JH
40 }
41 else {
42 die "Description does not match $name: $description";
43 }
44}
45
e7a9807a
JH
46my ($input, @categories) = @ARGV;
47
48open IN, "<$input";
49while (<IN>) {
11c6659d
ES
50 last if /^### command list/;
51}
52
72fe6a59 53my %cmds = ();
e7a9807a 54for (sort <IN>) {
72fe6a59
JH
55 next if /^#/;
56
57 chomp;
0bf15e74 58 my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
79d30668
JH
59 $attr = '' unless defined $attr;
60 push @{$cmds{$cat}}, [$name, " $attr "];
72fe6a59 61}
e7a9807a 62close IN;
72fe6a59 63
e7a9807a
JH
64for my $out (@categories) {
65 my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
72fe6a59
JH
66 open O, '>', "$out+" or die "Cannot open output file $out+";
67 for (@{$cmds{$cat}}) {
68 format_one(\*O, $_);
69 }
70 close O;
d7907392
JH
71
72 if (-f "$out" && compare("$out", "$out+") == 0) {
73 unlink "$out+";
74 }
75 else {
76 print STDERR "$out\n";
77 rename "$out+", "$out";
78 }
72fe6a59 79}