summaryrefslogtreecommitdiffstats
path: root/command.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-08-27 01:10:59 -0400
committerMike Frysinger <vapier@google.com>2019-08-28 03:54:11 +0000
commitae6cb08ae52d488a4cc6892f811c1c1acf8c3c12 (patch)
treec927415df288d9bf9076e758835db53cc633597d /command.py
parent3fc157285cb61d6a4faa55dc4f011fb94d598c20 (diff)
downloadgit-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 'command.py')
-rw-r--r--command.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/command.py b/command.py
index 8c5e2461..f7d20a22 100644
--- a/command.py
+++ b/command.py
@@ -98,6 +98,16 @@ class Command(object):
98 self.OptionParser.print_usage() 98 self.OptionParser.print_usage()
99 sys.exit(1) 99 sys.exit(1)
100 100
101 def ValidateOptions(self, opt, args):
102 """Validate the user options & arguments before executing.
103
104 This is meant to help break the code up into logical steps. Some tips:
105 * Use self.OptionParser.error to display CLI related errors.
106 * Adjust opt member defaults as makes sense.
107 * Adjust the args list, but do so inplace so the caller sees updates.
108 * Try to avoid updating self state. Leave that to Execute.
109 """
110
101 def Execute(self, opt, args): 111 def Execute(self, opt, args):
102 """Perform the action, after option parsing is complete. 112 """Perform the action, after option parsing is complete.
103 """ 113 """