Add a command line flag to disable .reviewboardrc

Review Request #10044 — Created June 28, 2018 and updated

mandeep
RBTools
master
e210501...
rbtools
brennie

One can now prevent the Review board server from reading .reviewboardrc
file by typing the command --diasble-reviewboardrc in the command
line.



Description From Last Updated

Can you undo your docstring changes?

brenniebrennie

To unit test this, we can extract the parsing and default-applying code out of run_from_argv and create_arg_parser into a method: ...

brenniebrennie

This is mostly true, except default IS supported by argparse.

brenniebrennie

Instead of doing this, we should check for action='append' and set the value to [] in our default checking code.

brenniebrennie

Here too

brenniebrennie

Missing a docstring.

brenniebrennie

We need to set self.config to a default, empty config (with e.g. ALIASES, etc) set in the else.

brenniebrennie

Instead of looping twice, we can loop once: ```python for option in self.all_options(): try: default = option.attrs['default'] except KeyError: # ...

brenniebrennie

Undo this, too

brenniebrennie
mandeep
Review request changed

People:

+brennie
brennie
  1. 
      
  2. Can you undo your docstring changes?

  3. To unit test this, we can extract the parsing and default-applying code out of run_from_argv and create_arg_parser into a method:

    def parse_args(self, argv):
        parser = argparse.ArgumentParser(
            prog=RB_MAIN,
            usage=self.usage(),
            add_help=False,
            formatter_lass=SmartHelpFormatter,
            argument_default=argparse.SUPPRESS)
    
        for option in self.option_list:
            option.add_to(parser)
    
        for option in self._global_options:
            opion.add_to(parser)
    
        options = parser.parse_args(argv[2:])
    
        if getattr(self.options, 'disable_reviewboardrc', False):
            config = {
                # .. default sane config
            }
        else:
            config = load_config()
    
            for option in self.all_options():
                # Apply values from config ...
    
        for option in self.all_options():
            # Figure out defaults ...
    
        return config, options
    
    def run_from_argv(self, argv):
        self.config, self.options = self.parse_args(argv)
        self.args = self.options.args
    
        # ...
    

    Then we can unit test parse_args and check the config, options it returns.

  4. rbtools/commands/__init__.py (Diff revision 1)
     
     
     
     
     

    This is mostly true, except default IS supported by argparse.

  5. rbtools/commands/__init__.py (Diff revision 1)
     
     

    Instead of doing this, we should check for action='append' and set the value to [] in our default checking code.

  6. rbtools/commands/__init__.py (Diff revision 1)
     
     

    Here too

  7. rbtools/commands/__init__.py (Diff revision 1)
     
     

    Missing a docstring.

  8. rbtools/commands/__init__.py (Diff revision 1)
     
     
     

    We need to set self.config to a default, empty config (with e.g. ALIASES, etc) set in the else.

  9. rbtools/commands/__init__.py (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    Instead of looping twice, we can loop once:

    ```python
    for option in self.all_options():
    try:
    default = option.attrs['default']
    except KeyError:
    # If the option does not have an explicit default, it may have an
    # implied default.
    action = option.attrs.get('action')

            if action == 'append':
                default = []
            elif action == 'store_true':
                default = False
            elif action == 'store_false':
                default = True
            else:
                # This option does not have a default.
                continue
    
        option_name = option.attrs['dest']
        if not hasattr(self.options, option_name):
            setattr(self.options, option_name, default)
    

    ``

  10. rbtools/commands/__init__.py (Diff revision 1)
     
     
     
     
     

    Undo this, too

  11. 
      
Loading...