diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-12-19 11:11:06 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-12-19 11:11:06 +0000 |
commit | c301c24bd07029d7e2e309d56e36ef34e6097b01 (patch) | |
tree | 20d6e7fa1ebb60f52fffae40dd9d6e51fdf426ff /cliapp/app.py | |
parent | 243e6d0d0b199cd1cf670b9a8ae8afdbae89f2c6 (diff) | |
download | cliapp-c301c24bd07029d7e2e309d56e36ef34e6097b01.tar.gz |
Add a way to compute setting values
Diffstat (limited to 'cliapp/app.py')
-rw-r--r-- | cliapp/app.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/cliapp/app.py b/cliapp/app.py index 88eed13..f21726a 100644 --- a/cliapp/app.py +++ b/cliapp/app.py @@ -222,6 +222,20 @@ class Application(object): logging.info('%s version %s ends normally' % (self.settings.progname, self.settings.version)) + def compute_setting_values(self, settings): + '''Compute setting values after configs and options are parsed. + + You can override this method to implement a default value for + a setting that is dependent on another setting. For example, + you might have settings "url" and "protocol", where protocol + gets set based on the schema of the url, unless explicitly + set by the user. So if the user sets just the url, to + "http://www.example.com/", the protocol would be set to + "http". If the user sets both url and protocol, the protocol + does not get modified by compute_setting_values. + + ''' + def add_subcommand(self, name, func, arg_synopsis=None): '''Add a subcommand. @@ -408,9 +422,10 @@ class Application(object): ''' - return self.settings.parse_args(args, configs_only=configs_only, - arg_synopsis=self.arg_synopsis, - cmd_synopsis=self.cmd_synopsis) + return self.settings.parse_args( + args, configs_only=configs_only, arg_synopsis=self.arg_synopsis, + cmd_synopsis=self.cmd_synopsis, + compute_setting_values=self.compute_setting_values) def setup(self): '''Prepare for process_args. |