| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use File::Slurp; | ||
| 6 | |||
| 7 | # replace __USAGE__ with the output of treex --help | ||
| 8 | # in lib/Treex/Core/Run.pm | ||
| 9 | my $module_filename = 'lib/Treex/Core/Run.pm'; | ||
| 10 | |||
| 11 | my $treex = 'bin/treex'; | ||
| 12 | if ( !-x $treex ) { | ||
| 13 | $treex = 'treex'; | ||
| 14 | } | ||
| 15 | if ( -x $treex ) { | ||
| 16 | print STDERR "Reading treex usage from $treex --help\n"; | ||
| 17 | my $usage = `$treex --help 2>&1`; | ||
| 18 | |||
| 19 | # leading space will make it verbatim | ||
| 20 | $usage = join "\n", map {" $_"} split( /\n/, $usage ); | ||
| 21 | |||
| 22 | my $module_content = File::Slurp::read_file( $module_filename, binmode => ':utf8' ); | ||
| 23 | |||
| 24 | if ( $module_content =~ s/__USAGE__/$usage/ ) { | ||
| 25 | File::Slurp::write_file( $module_filename, { binmode => ':utf8' }, $module_content ); | ||
| 26 | |||
| 27 | #open my $MODULE, '>:utf8', $module_filename or die $!; | ||
| 28 | #print $MODULE $module_content; | ||
| 29 | #close $MODULE; | ||
| 30 | |||
| 31 | print STDERR "usage filled into $module_filename\n"; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | else { | ||
| 35 | print STDERR "Cannot fill usage into $module_filename\n"; | ||
| 36 | } |