X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=script%2Fdbicadmin;h=16e97fecdd2f11e3cbfb5bac3964757e8ac27e0c;hb=64ae166780d0cb2b9577e506da9b9b240c146d20;hp=ee7bbbbc7a43b65d12dcd57be9bfddc128532ed7;hpb=6f720a197f55809153c8d4fa894e6d335c1f3bcd;p=dbsrgits%2FDBIx-Class.git diff --git a/script/dbicadmin b/script/dbicadmin index ee7bbbb..16e97fe 100755 --- a/script/dbicadmin +++ b/script/dbicadmin @@ -1,12 +1,13 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; BEGIN { use DBIx::Class; - die ( "The following modules are required for the dbicadmin utility\n" + die ( 'The following modules are required for the dbicadmin utility: ' . DBIx::Class::Optional::Dependencies->req_missing_for ('admin_script') + . "\n" ) unless DBIx::Class::Optional::Dependencies->req_ok_for ('admin_script'); } @@ -15,7 +16,7 @@ use DBIx::Class::Admin::Descriptive; use DBIx::Class::Admin; my $short_description = "utility for administrating DBIx::Class schemata"; -my $synopsis_text =qq{ +my $synopsis_text =q| deploy a schema to a database %c --schema=MyApp::Schema \ --connect='["dbi:SQLite:my.db", "", ""]' \ @@ -25,72 +26,88 @@ my $synopsis_text =qq{ %c --schema=MyApp::Schema --class=Employee \ --connect='["dbi:SQLite:my.db", "", ""]' \ --op=update --set='{ "name": "New_Employee" }' -} -; +|; my ($opts, $usage) = describe_options( "%c: %o", ( ['Actions'], ["action" => hidden => { one_of => [ - ['create|c' => 'Create version diffs needs preversion',], - ['upgrade|U' => 'Upgrade the database to the current schema '], - ['install|I' => 'Install the schema version tables to an existing database',], - ['deploy|d' => 'Deploy the schema to the database',], - ['select|s' => 'Select data from the schema', ], - ['insert|i' => 'Insert data into the schema', ], - ['update|u' => 'Update data in the schema', ], - ['delete|D' => 'Delete data from the schema',], + ['create' => 'Create version diffs needs preversion',], + ['upgrade' => 'Upgrade the database to the current schema '], + ['install' => 'Install the schema version tables to an existing database',], + ['deploy' => 'Deploy the schema to the database',], + ['select' => 'Select data from the schema', ], + ['insert' => 'Insert data into the schema', ], + ['update' => 'Update data in the schema', ], + ['delete' => 'Delete data from the schema',], ['op:s' => 'compatiblity option all of the above can be suppied as --op='], - ['help|h' => 'display this help', { implies => { schema_class => 'main' } } ], - ['pod' => 'Output this usage as pod', { implies => { schema_class => 'main' } } ], + ['help' => 'display this help', { implies => { schema_class => '__dummy__' } } ], + ['selfinject-pod' => 'hidden', { implies => { schema_class => '__dummy__' } } ], ], required=> 1 }], ['Arguments'], - ['schema-class|schema|C:s' => 'The class of the schema to load', { required => 1 } ], - ['resultset|resultset_class|class|r:s' => 'The resultset to operate on for data manipulation' ], - ['config-stanza|S:s' => 'Where in the config to find the connection_info, supply in form MyApp::Model::DB',], - ['config|f:s' => 'Supply the config file for parsing by Config::Any', { depends => 'config_stanza'} ], - ['connect-info|n:s%' => 'Supply the connect info as additonal options ie -I dsn= user= password= '], + ['schema-class:s' => 'The class of the schema to load', { required => 1 } ], + ['resultset|resultset-class|class:s' => 'The resultset to operate on for data manipulation' ], + ['config-stanza:s' => 'Where in the config to find the connection_info, supply in form MyApp::Model::DB',], + ['config:s' => 'Supply the config file for parsing by Config::Any', { depends => 'config_stanza'} ], + ['connect-info:s%' => 'Supply the connect info as additonal options ie -I dsn= user= password= '], ['connect:s' => 'Supply the connect info as a json string' ], - ['sql-dir|q:s' => 'The directory where sql diffs will be created'], - ['sql-type|t:s' => 'The RDBMs flavour you wish to use'], - ['version|v:i' => 'Supply a version install'], - ['preversion|p:s' => 'The previous version to diff against',], + ['sql-dir:s' => 'The directory where sql diffs will be created'], + ['sql-type:s' => 'The RDBMs flavour you wish to use'], + ['version:i' => 'Supply a version install'], + ['preversion:s' => 'The previous version to diff against',], ['set:s' => 'JSON data used to perform data operations' ], ['attrs:s' => 'JSON string to be used for the second argument for search'], ['where:s' => 'JSON string to be used for the where clause of search'], ['force' => 'Be forceful with some operations'], ['trace' => 'Turn on DBIx::Class trace output'], ['quiet' => 'Be less verbose'], + ['I:s@' => 'Same as perl\'s -I, prepended to current @INC'], ) ); die "please only use one of --config or --connect-info\n" if ($opts->{config} and $opts->{connect_info}); -if($opts->{pod}) { +if($opts->{selfinject_pod}) { + + die "This is an internal method, do not call!!!\n" + unless $ENV{MAKELEVEL}; + $usage->synopsis($synopsis_text); $usage->short_description($short_description); - print $usage->pod(); - exit 0; + exec ( + $^X, + qw/-p -0777 -i -e/, + ( + 's/^# auto_pod_begin.*^# auto_pod_end/' + . quotemeta($usage->pod) + . '/ms' + ), + __FILE__ + ); +} + +# FIXME - lowercasing will eventually go away when Getopt::Long::Descriptive is fixed +if($opts->{i}) { + require lib; + lib->import( @{delete $opts->{i}} ); } if($opts->{help}) { - $usage->die(); + $usage->die(); } # option compatability mangle if($opts->{connect}) { $opts->{connect_info} = delete $opts->{connect}; } - my $admin = DBIx::Class::Admin->new( %$opts ); - my $action = $opts->{action}; $action = $opts->{op} if ($action eq 'op'); -print "Performig action $action...\n"; +print "Performing action $action...\n"; my $res = $admin->$action(); if ($action eq 'select') { @@ -111,28 +128,12 @@ if ($action eq 'select') { } -#__END__ -# -#=begin pod_begin -# -#BEGIN MARKER FOR DYNAMIC POD -# -#=end pod_begin -# -#=begin pod_end -# -#END MARKER FOR DYNAMIC POD -# -#=end pod_end -# -#=head1 AUTHOR -# -#See L. -# -#=head1 LICENSE +__END__ + +# auto_pod_begin # -#You may distribute this code under the same terms as Perl itself +# This will be replaced by the actual pod when selfinject-pod is invoked # -#=cut +# auto_pod_end # vim: et ft=perl