Files
cgpcli/cgp-api-check

100 lines
2.4 KiB
Perl
Executable File

#!/usr/bin/perl
use strict;
use warnings;
use YAML;
my @argv = @ARGV;
my @files;
my $cli_txt = 'docs/api/CLI.txt';
my %go_funcs;
my $verbose;
while (@argv) {
my $item = shift @argv;
if ($item eq '-v') {
$verbose = 1;
} elsif ($item eq '-a') {
$cli_txt = shift @argv;
} else {
push @files, $item;
}
}
die "Usage: $0 [-v ] [-a CLI.txt] <source.go|*.go>\n" if @files == 0;
# 1. Индексируем функции в Go файлах
foreach my $file (@files) {
open my $fh, '<', $file or die "Can't open $file: $!";
while (<$fh>) {
# Извлекаем имя метода (экспортируемого)
if (/func\s+\([^)]+\)\s+([A-Z]\w*)\s*\(/) {
$go_funcs{lc $1} = $1;
}
}
close $fh;
}
# 2. Парсим CLI.txt по разделам
my %sections;
my $current_section = 'fake';
open my $fh_cli, '<', $cli_txt or die "Can't open $cli_txt: $!";
while (<$fh_cli>) {
chomp;
next if /^\s*$/;
next if /^\s*[_]{10,}/;
next if /^Command Line Interface|^CLI Access|^CLI Syntax|^Index/;
last if /^Index/;
# Определение начала раздела
if (/^[A-Z][A-Za-z-]+/) {
$current_section = $_;
next;
}
# Определение команды
if (/^\s{3}([A-Z]{4,})/) {
my $cmd = $1;
$sections{$current_section}{$cmd} = 1;
}
}
close $fh_cli;
delete $sections{fake};
# 3. Вывод отчета
print "CGP CLI IMPLEMENTATION REPORT\n";
print "=" x 29 . "\n";
foreach my $sec (sort keys %sections) {
my @cmds = sort keys %{$sections{$sec}};
my @missing;
my $found = 0;
# Сначала считаем попадания
foreach my $cmd (@cmds) {
if (exists $go_funcs{lc $cmd}) {
$found++;
} else {
push @missing, $cmd;
}
}
# Выводим раздел только если есть хотя бы одна реализованная функция
if ($found > 0 || $verbose) {
print "\nSECTION: $sec\n";
print "-" x (length($sec) + 9) . "\n";
printf "Status: %d/%d implemented\n", $found, scalar @cmds;
if (@missing) {
print "Missing in Go SDK:\n";
print " - $_\n" for @missing;
} else {
print " [+] All commands from this section are implemented!\n";
}
}
}
exit;