xref: /curl/.github/scripts/cleancmd.pl (revision 8b1f3aa6)
1#!/usr/bin/perl
2# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3#
4# SPDX-License-Identifier: curl
5#
6# Input: a cmdline docs markdown, it gets modfied *in place*
7#
8# The main purpose is to strip off the leading meta-data part, but also to
9# clean up whatever else the spell checker might have a problem with that we
10# still deem is fine.
11
12my $header = 1;
13while(1) {
14    # set this if the markdown has no meta-data header to skip
15    if($ARGV[0] eq "--no-header") {
16        shift @ARGV;
17        $header = 0;
18    }
19    else {
20        last;
21    }
22}
23
24my $f = $ARGV[0];
25
26open(F, "<$f") or die;
27
28my $ignore = $header;
29my $sepcount = 0;
30my @out;
31while(<F>) {
32    if(/^---/ && $header) {
33        if(++$sepcount == 2) {
34            $ignore = 0;
35        }
36        next;
37    }
38    next if($ignore);
39
40    # strip out all long command line options
41    $_ =~ s/--[a-z0-9-]+//g;
42
43    # strip out https URLs, we don't want them spellchecked
44    $_ =~ s!https://[a-z0-9\#_/.-]+!!gi;
45
46    push @out, $_;
47}
48close(F);
49
50if(!$ignore) {
51    open(O, ">$f") or die;
52    print O @out;
53    close(O);
54}
55