diff options
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -84,18 +84,34 @@ class Command(object): | |||
84 | usage = 'repo %s' % self.NAME | 84 | usage = 'repo %s' % self.NAME |
85 | epilog = 'Run `repo help %s` to view the detailed manual.' % self.NAME | 85 | epilog = 'Run `repo help %s` to view the detailed manual.' % self.NAME |
86 | self._optparse = optparse.OptionParser(usage=usage, epilog=epilog) | 86 | self._optparse = optparse.OptionParser(usage=usage, epilog=epilog) |
87 | self._CommonOptions(self._optparse) | ||
87 | self._Options(self._optparse) | 88 | self._Options(self._optparse) |
88 | return self._optparse | 89 | return self._optparse |
89 | 90 | ||
90 | def _Options(self, p): | 91 | def _CommonOptions(self, p, opt_v=True): |
91 | """Initialize the option parser. | 92 | """Initialize the option parser with common options. |
93 | |||
94 | These will show up for *all* subcommands, so use sparingly. | ||
95 | NB: Keep in sync with repo:InitParser(). | ||
92 | """ | 96 | """ |
97 | g = p.add_option_group('Logging options') | ||
98 | opts = ['-v'] if opt_v else [] | ||
99 | g.add_option(*opts, '--verbose', | ||
100 | dest='output_mode', action='store_true', | ||
101 | help='show all output') | ||
102 | g.add_option('-q', '--quiet', | ||
103 | dest='output_mode', action='store_false', | ||
104 | help='only show errors') | ||
105 | |||
93 | if self.PARALLEL_JOBS is not None: | 106 | if self.PARALLEL_JOBS is not None: |
94 | p.add_option( | 107 | p.add_option( |
95 | '-j', '--jobs', | 108 | '-j', '--jobs', |
96 | type=int, default=self.PARALLEL_JOBS, | 109 | type=int, default=self.PARALLEL_JOBS, |
97 | help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS) | 110 | help='number of jobs to run in parallel (default: %s)' % self.PARALLEL_JOBS) |
98 | 111 | ||
112 | def _Options(self, p): | ||
113 | """Initialize the option parser with subcommand-specific options.""" | ||
114 | |||
99 | def _RegisteredEnvironmentOptions(self): | 115 | def _RegisteredEnvironmentOptions(self): |
100 | """Get options that can be set from environment variables. | 116 | """Get options that can be set from environment variables. |
101 | 117 | ||
@@ -120,6 +136,11 @@ class Command(object): | |||
120 | self.OptionParser.print_usage() | 136 | self.OptionParser.print_usage() |
121 | sys.exit(1) | 137 | sys.exit(1) |
122 | 138 | ||
139 | def CommonValidateOptions(self, opt, args): | ||
140 | """Validate common options.""" | ||
141 | opt.quiet = opt.output_mode is False | ||
142 | opt.verbose = opt.output_mode is True | ||
143 | |||
123 | def ValidateOptions(self, opt, args): | 144 | def ValidateOptions(self, opt, args): |
124 | """Validate the user options & arguments before executing. | 145 | """Validate the user options & arguments before executing. |
125 | 146 | ||