From ae6cb08ae52d488a4cc6892f811c1c1acf8c3c12 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 27 Aug 2019 01:10:59 -0400 Subject: split out cli validation from execution A common pattern in our subcommands is to verify the arguments & options before executing things. For some subcommands, that check stage is quite long which makes the execution function even bigger. Lets split that logic out of the execute phase so it's easier to manage these. This is most noticeable in the sync subcommand whose Execute func is quite large, and the option checking makes up ~15% of it. The manifest command's Execute can be simplified significantly as the optparse configuration always sets output_file to a string. Change-Id: I7097847ff040e831345e63de6b467ee17609990e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234834 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- subcmds/start.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'subcmds/start.py') diff --git a/subcmds/start.py b/subcmds/start.py index 0c60d78c..5d4c9c01 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -41,15 +41,16 @@ revision specified in the manifest. dest='all', action='store_true', help='begin branch in all projects') - def Execute(self, opt, args): + def ValidateOptions(self, opt, args): if not args: self.Usage() nb = args[0] if not git.check_ref_format('heads/%s' % nb): - print("error: '%s' is not a valid name" % nb, file=sys.stderr) - sys.exit(1) + self.OptionParser.error("'%s' is not a valid name" % nb) + def Execute(self, opt, args): + nb = args[0] err = [] projects = [] if not opt.all: -- cgit v1.2.3-54-g00ecf