doc: return fields for customer_info, RT#84796
[freeside.git] / bin / generate-table-module
index fcc3f1d..37a5812 100755 (executable)
@@ -1,7 +1,11 @@
 #!/usr/bin/perl
 
+use strict;
+use vars qw( $opt_n );
 use FS::Schema qw( dbdef_dist );
+use Getopt::Std;
 
+getopts('n');
 my $table = shift;
 
 ###
@@ -13,6 +17,7 @@ my %ut = ( #just guesses
   'number'  => 'float',
   'varchar' => 'text',
   'text'    => 'text',
+  'serial'  => 'number',
 );
 
 my $dbdef_table = dbdef_dist->table($table)
@@ -30,10 +35,12 @@ while (my $line = <SRC>) {
   if ( $line =~ /^=item\s+field\s+-\s+description\s*$/ ) {
 
     foreach my $column ( $dbdef_table->columns ) {
-      print DEST "=item $column - ";
-      print DEST "primary key"
-        if $column eq $primary_key;
-      print DEST "\n\n";
+      print DEST "=item $column\n\n";
+      if ( $column eq $primary_key ) {
+        print DEST "primary key\n\n";
+      } else {
+        print DEST "$column\n\n";
+      }
     }
     next;
 
@@ -63,6 +70,14 @@ close SRC;
 close DEST;
 
 ###
+# add to FS/FS/Mason.pm
+###
+
+my $magic = '# Sammath Naur';
+system("perl -pi -e 's/$magic/use FS::$table;\n  $magic/' FS/FS/Mason.pm")
+  unless $opt_n;
+
+###
 # add FS/t/table.t
 ###
 
@@ -80,10 +95,10 @@ close TEST;
 # add them to MANIFEST
 ###
 
-system('cvs edit FS/MANIFEST');
-
 open(MANIFEST,">>FS/MANIFEST") or die $!;
 print MANIFEST "FS/$table.pm\n",
                "t/$table.t\n";
 close MANIFEST;
 
+system("git add FS/FS/$table.pm FS/t/$table.t");
+