X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=mig-bin%2Fmig-gsheet;h=fdf0cf8f78bfcc2c2b9cb07e635c930267a9f6a9;hp=86654f8e86c39a2a24f34fcacca043504c3a5034;hb=337680650a86c2fb1c5d5bddfb4053a56fb9964b;hpb=abd558500e6bc82e02c9617b9627799ae16e7a4f diff --git a/mig-bin/mig-gsheet b/mig-bin/mig-gsheet index 86654f8..fdf0cf8 100755 --- a/mig-bin/mig-gsheet +++ b/mig-bin/mig-gsheet @@ -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_ -}