| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Getopt::Long; |
| 7 |
Getopt::Long::Configure("pass_through"); |
| 8 |
use Data::Dumper; |
| 9 |
use Google::ProtocolBuffers; |
| 10 |
|
| 11 |
our $VERSION = $Google::ProtocolBuffers::VERSION; |
| 12 |
|
| 13 |
my $path = []; |
| 14 |
my $help = 0; |
| 15 |
my $debug = 0; |
| 16 |
my $verbose = 0; |
| 17 |
my $version = 0; |
| 18 |
my $decode_raw = 0; |
| 19 |
my $oFile = 0; |
| 20 |
my $perl_out = 0; |
| 21 |
my $package_name = ''; |
| 22 |
my $proto_file = 0; |
| 23 |
|
| 24 |
GetOptions( |
| 25 |
'proto_path|I=s@' => \$path, |
| 26 |
'help|h' => \$help, |
| 27 |
'debug|d' => \$debug, |
| 28 |
'verbose+' => \$verbose, |
| 29 |
'perl_out=s' => \$perl_out, |
| 30 |
'version|v' => \$version, |
| 31 |
'package|p=s' => \$package_name, |
| 32 |
); |
| 33 |
|
| 34 |
## TODO: multi-proto support |
| 35 |
$proto_file = $ARGV[$#ARGV]; |
| 36 |
pop(@ARGV); |
| 37 |
|
| 38 |
# test for -Ilib |
| 39 |
foreach (@ARGV){ |
| 40 |
if(/^-I/){ |
| 41 |
$_ =~ s/^-I//; |
| 42 |
push(@{$path},$_); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if($version){ |
| 47 |
print "Google::ProtocolBuffers ".$VERSION."\n"; |
| 48 |
exit(0); |
| 49 |
} |
| 50 |
|
| 51 |
die usage() if($help || !$proto_file); |
| 52 |
|
| 53 |
sub usage { |
| 54 |
return <<EOF; |
| 55 |
Usage: $0 [OPTION] PROTO_FILE |
| 56 |
Parse PROTO_FILE and generate output based on the options given: |
| 57 |
-IPATH, --proto_path=PATH Specify the directory in which to search for |
| 58 |
imports. May be specified multiple times; |
| 59 |
directories will be searched in order. If not |
| 60 |
given, the current working directory is used. |
| 61 |
--version Show version info and exit. |
| 62 |
-h, --help Show this text and exit. |
| 63 |
|
| 64 |
--perl_out=OUT_FILE Generate the Perl source file. (eg: lib/App/MyPackage.pm) |
| 65 |
-p, --package=NANE Specify a package name (eg: App::MyPackage) to be appended |
| 66 |
in header |
| 67 |
|
| 68 |
Version: $VERSION |
| 69 |
EOF |
| 70 |
} |
| 71 |
|
| 72 |
Google::ProtocolBuffers->parsefile( |
| 73 |
$proto_file, |
| 74 |
{ |
| 75 |
generate_code => $perl_out, |
| 76 |
create_accessors => 1, |
| 77 |
follow_best_practice => 1, |
| 78 |
include_dir => $path, |
| 79 |
package_name => $package_name, |
| 80 |
} |
| 81 |
); |