Browse Source

Basic config file misconfig erroring

spesk1 4 years ago
parent
commit
171eba46bd
2 changed files with 10 additions and 4 deletions
  1. 1 1
      README.md
  2. 9 3
      lib/Gsg/ConfigParse.pm

+ 1 - 1
README.md

@@ -16,6 +16,7 @@ DONE:
 * Line numbers for file browsing
 * Diff highlighting for log
 * Show git:// address for cloning (configurable via config file)
+* Support detection of misconfig of config file (pretty basic at this stage)
 
 TODO:
 * Get diff stat for top of log index links
@@ -24,7 +25,6 @@ TODO:
 * README.md markdown renderer/parser / display in project index
 * (Stretch Goal) HTML based syntax highlighting for files
 * (Stretch Goal) Accompanying daemon that will auto regen the website
-* Support detection of misconfig of config file
 
 ## Framework Plans ##
 * gsg -- Perl script to generate the site, uses modules below

+ 9 - 3
lib/Gsg/ConfigParse.pm

@@ -22,13 +22,12 @@ sub parse_gsg_config($$) {
 	my $cat_cmd = findBin("cat",$logger);
 	my @config_lines = split("\n",shellex("$cat_cmd $config_path",$logger));
 	my %config_hash;
+	my $line_counter = 1;
 	foreach my $line ( @config_lines ) {
 		chomp $line;
 		if ( $line =~ m/^(.*)\ =\ "(.*)"$/ ) {
 			$config_hash{$1} = $2;
-		}
-
-		if ( $line =~ m/^(.*)\ =\ \[(.*)\]/ ) {
+		} elsif ( $line =~ m/^(.*)\ =\ \[(.*)\]/ ) {
 			my @trimmed_vals;
 			my @vals = split(",",$2);
 			foreach my $val (@vals) {
@@ -36,7 +35,14 @@ sub parse_gsg_config($$) {
 				push(@trimmed_vals,trim($1));
 			}
 			$config_hash{$1} = \@trimmed_vals;
+		} elsif ( $line =~ m/^\#/ ) {
+			next;
+		} else {
+			$logger->error("Couldn't parse config line $line_counter : $line : exiting");
+			exit 1;
 		}
+
+		$line_counter++;
 	}
 
 	return %config_hash;