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/manifest.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'subcmds/manifest.py') diff --git a/subcmds/manifest.py b/subcmds/manifest.py index 07fa323a..768f072e 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py @@ -73,14 +73,9 @@ in a Git repository for use during future 'repo init' invocations. if opt.output_file != '-': print('Saved manifest to %s' % opt.output_file, file=sys.stderr) - def Execute(self, opt, args): + def ValidateOptions(self, opt, args): if args: self.Usage() - if opt.output_file is not None: - self._Output(opt) - return - - print('error: no operation to perform', file=sys.stderr) - print('error: see repo help manifest', file=sys.stderr) - sys.exit(1) + def Execute(self, opt, args): + self._Output(opt) -- cgit v1.2.3-54-g00ecf