Browse Source

Updated README and added arg parsing sub

Spesk1 5 years ago
parent
commit
c0c671442a
2 changed files with 43 additions and 7 deletions
  1. 4 1
      README.md
  2. 39 6
      sg

+ 4 - 1
README.md

@@ -15,6 +15,9 @@ Features:
 --configure-local-user
 * configure local user in .git/config
 
+--add-upstream
+* append upstream config to fork config
+
 Stuff to fix:
 * enforce req. of logging object in all relevant Git.pm subs
-* sub in sg for sane processing/resolution of arguments (currently dangerous if passing all/poorly ordered opts)
+* multipule TODO:'s in various files

+ 39 - 6
sg

@@ -104,8 +104,46 @@ if ( scalar keys %args < 1 ) {
 	printHelp();
 }
 
+###
+# TODO: This args processing is better and more predictable than it was, bit there is still
+# likely a lot of room for improvement...
+###
+
+sub parseArgs {
+
+	if ( defined $args{'view'} && scalar keys %args > 1 ) {
+		print "Can't pass other args with --view\n";
+		exit 1;
+	}
+
+	if ( defined $args{'dump-config'} && scalar keys %args > 1 ) {
+		print "Can't pass other args with --dump-config\n";
+		exit 1;
+	}
+
+	if ( defined $args{'reset-from-master'} && scalar keys %args > 1 ) {
+		print "Can't pass other args with --reset-from-master\n";
+		exit 1;
+	}
 
-# This functionality is mainly here to test building out Git.pm, and doesn't really offer anything that regular git doesn't
+	if ( defined $args{'push-all'} ) {
+		foreach my $arg ( keys %args ) {
+			if ( $arg eq "interactive" || $arg eq "commit-msg" || $arg eq "push-all" ) {
+				next;
+			} else {
+				print "Can only pass --interactive and --commit-msg with --push-all\n";
+				exit 1;
+			}
+		}
+	}
+
+
+
+}
+
+parseArgs();
+
+# TODO: This sub could be more concise with a sub to print array refs
 if ( defined $args{'view'} ) {
 	my ( $untrackedRef, $modifiedRef, $addedRef, $deletedRef ) = returnState($logger);
 	my $refs = shellex("$gitCmd show-ref",$logger);
@@ -155,11 +193,6 @@ if ( defined $args{'view'} ) {
 	}
 }
 
-###
-# TODO: This args processing is dangerous and incomplete, need to write an args processor function
-###
-
-# This functionality is mainly here to test building out Git.pm, and doesn't really offer anything that regular git doesn't
 if ( defined $args{'push-all'} ) {
 
 	my ( $untrackedRef, $modifiedRef ) = returnState($logger);