Permalink
Browse files

add command line script to call sqlbeautify

  • Loading branch information...
1 parent e6d169a commit 94496bad7675f632de05268e893b375babc4d560 @szabgab szabgab committed Jul 17, 2011
Showing with 51 additions and 0 deletions.
  1. +1 −0 Build.PL
  2. +1 −0 MANIFEST
  3. +49 −0 script/sqlbeautify
View
@@ -13,6 +13,7 @@ my $builder = Module::Build->new(
},
add_to_cleanup => [ 'SQL-Beautify-*' ],
create_makefile_pl => 'traditional',
+ script_files => ['script/sqlbeautify'],
meta_merge => {
resources => {
repository => 'https://github.com/jkramer/sql-beautify'
View
@@ -3,6 +3,7 @@ Changes
lib/SQL/Beautify.pm
MANIFEST
README
+script/sqlbeautify
t/add_keywords.t
t/color.t
t/custom_rules.t
View
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Getopt::Long qw(GetOptions);
+use SQL::Beautify;
+
+
+my %opt;
+
+usage() if not @ARGV;
+GetOptions(\%opt,
+ 'spaces=i',
+ 'help',
+) or usage();
+usage() if $opt{help};
+usage() if not @ARGV;
+
+my $sql = SQL::Beautify->new(%opt);
+
+foreach my $file (@ARGV) {
+ my $original_sql = read_file($file);
+ $sql->query($original_sql);
+ my $nice_sql = $sql->beautify;
+ print $nice_sql;
+}
+
+
+sub read_file {
+ my $file = shift;
+ open my $fh, '<', $file or die;
+ local $/ = undef;
+ my $content = <$fh>;
+ close $fh;
+ return $content;
+}
+
+sub usage {
+ print <<"END_USAGE";
+v$SQL::Beautify::VERSION
+Usage: $0 [options] FILEs
+
+ --spaces 4 - number of indentation spaces (defaults to 4)
+
+ --help - this help
+END_USAGE
+ exit;
+}
+

0 comments on commit 94496ba

Please sign in to comment.