diff options
author | Mike Frysinger <vapier@google.com> | 2019-08-27 01:10:59 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2019-08-28 03:54:11 +0000 |
commit | ae6cb08ae52d488a4cc6892f811c1c1acf8c3c12 (patch) | |
tree | c927415df288d9bf9076e758835db53cc633597d /subcmds/abandon.py | |
parent | 3fc157285cb61d6a4faa55dc4f011fb94d598c20 (diff) | |
download | git-repo-ae6cb08ae52d488a4cc6892f811c1c1acf8c3c12.tar.gz |
split out cli validation from executionv1.13.5
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 <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/abandon.py')
-rw-r--r-- | subcmds/abandon.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 319262bd..cd1d0c40 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py | |||
@@ -37,19 +37,19 @@ It is equivalent to "git branch -D <branchname>". | |||
37 | dest='all', action='store_true', | 37 | dest='all', action='store_true', |
38 | help='delete all branches in all projects') | 38 | help='delete all branches in all projects') |
39 | 39 | ||
40 | def Execute(self, opt, args): | 40 | def ValidateOptions(self, opt, args): |
41 | if not opt.all and not args: | 41 | if not opt.all and not args: |
42 | self.Usage() | 42 | self.Usage() |
43 | 43 | ||
44 | if not opt.all: | 44 | if not opt.all: |
45 | nb = args[0] | 45 | nb = args[0] |
46 | if not git.check_ref_format('heads/%s' % nb): | 46 | if not git.check_ref_format('heads/%s' % nb): |
47 | print("error: '%s' is not a valid name" % nb, file=sys.stderr) | 47 | self.OptionParser.error("'%s' is not a valid branch name" % nb) |
48 | sys.exit(1) | ||
49 | else: | 48 | else: |
50 | args.insert(0,None) | 49 | args.insert(0, "'All local branches'") |
51 | nb = "'All local branches'" | ||
52 | 50 | ||
51 | def Execute(self, opt, args): | ||
52 | nb = args[0] | ||
53 | err = defaultdict(list) | 53 | err = defaultdict(list) |
54 | success = defaultdict(list) | 54 | success = defaultdict(list) |
55 | all_projects = self.GetProjects(args[1:]) | 55 | all_projects = self.GetProjects(args[1:]) |