adding load report file for resource mate
[migration-tools.git] / mig-bin / mig-gsheet
index 86654f8..fdf0cf8 100755 (executable)
@@ -11,6 +11,7 @@ use Storable;
 use DBI;
 use FindBin;
 use lib "$FindBin::Bin/";
+my $mig_bin = "$FindBin::Bin/";
 use Mig;
 use strict;
 use Env qw(
@@ -22,7 +23,7 @@ use Cwd 'abs_path';
 use Pod::Usage;
 use Data::Dumper;
 
-my $mig_bin = "$FindBin::Bin/";
+pod2usage(-verbose => 2) if defined $ARGV[0] && $ARGV[0] eq '--help';
 
 Mig::die_if_no_env_migschema();
 die_if_gsheet_tracked_table_does_not_exist();
@@ -65,8 +66,7 @@ foreach my $arg (@ARGV) {
     }
 }
 
-abort('invalid value for --export') unless ($cmd_export eq 'on' or $cmd_export eq 'off');
-abort('must specify --push or --pull') unless (defined $cmd_push or defined $cmd_pull);
+abort('must specify --push (db->worksheets) or --pull (worksheets->db)') unless (defined $cmd_push or defined $cmd_pull);
 if (defined $cmd_push and defined $cmd_pull) { abort('you can not specify both a --push and --pull on the same command'); }
 
 my $dbh = Mig::db_connect();
@@ -98,8 +98,6 @@ if (defined $cmd_pull) {
         my @rows = $pull_ws->rows;
         my @content;
         map { $content[$_->row - 1][$_->col - 1] = $_->content } $pull_ws->cells;
-        #print Dumper($pull_ws->cells);
-        #print Dumper(@content);
         my @tab_headers = shift @content;
         my $tab_headers_length = $#{ $tab_headers[0] };
         my @pg_headers;
@@ -170,7 +168,6 @@ if (defined $cmd_push) {
             push @content, $record;
         }
 
-        #print Dumper(@content); 
         foreach my $fillsheet (@content) {
             my $new_row = $push_ws->add_row (
                 $fillsheet
@@ -355,7 +352,6 @@ sub truncate_table {
 sub abort {
     my $msg = shift;
     print STDERR "$0: $msg", "\n";
-    print_usage();
     exit 1;
 }
 
@@ -388,23 +384,4 @@ sub connect_gsheet {
     return $spreadsheet;
 }
 
-sub print_usage {
-    print <<_USAGE_;
-
-Mig gsheet is for synchronizing data between migration postgresql tables 
-and Google Sheets.  It accepts the following command line arguments:
-
---push table_name or all
-
---pull worksheet_name or all
 
-Either --push or --pull must be present and it must be one or the other.
-
---export on or off  
-
-Export will default to off if not declared.  If on it will export to tab 
-separated tables the tables being pushed or worksheets being pulled with 
-timestamps.
-
-_USAGE_
-}