def _mixin_setup(self): group = self.output_options_group = optparse.OptionGroup( self, "Output Options", "Configure your preferred output format" ) self.add_option_group(group) group.add_option( '--raw-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command in ' 'raw python form, this is suitable for re-reading the ' 'output into an executing python script with eval.'.format( self.get_prog_name() )) ) group.add_option( '--yaml-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command in ' 'yaml.'.format(self.get_prog_name())) ) group.add_option( '--json-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command in ' 'json.'.format(self.get_prog_name())) ) if self._include_text_out_: group.add_option( '--text-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command ' 'in the same form the shell would.'.format( self.get_prog_name() )) ) outputters = loader.outputters( config.minion_config( '/etc/salt/minion', check_dns=False ) ) group.add_option( '--out', '--output', dest='output', choices=outputters.keys(), help=( 'Print the output from the \'{0}\' command using the ' 'specified outputter. One of {1}.'.format( self.get_prog_name(), ', '.join([repr(k) for k in outputters]) ) ) ) group.add_option( '--out-indent', '--output-indent', dest='output_indent', default=None, type=int, help=('Print the output indented by the provided value in spaces. ' 'Negative values disables indentation. Only applicable in ' 'outputters that support indentation.') ) group.add_option( '--no-color', default=False, action='store_true', help='Disable all colored output' ) for option in self.output_options_group.option_list: def process(opt): default = self.defaults.get(opt.dest) if getattr(self.options, opt.dest, default) is False: return if opt.dest not in ('out', 'output_indent', 'no_color'): msg = ( 'The option {0} is deprecated. Please consider using ' '\'--out {1}\' instead.'.format( opt.get_opt_string(), opt.dest.split('_', 1)[0] ) ) if version.__version_info__ >= (0, 10, 7): # XXX: CLEAN THIS CODE WHEN 0.10.8 is about to come out self.error(msg) elif log.is_console_configured(): logging.getLogger(__name__).warning(msg) else: sys.stdout.write('WARNING: {0}\n'.format(msg)) self.selected_output_option = opt.dest funcname = 'process_{0}'.format(option.dest) if not hasattr(self, funcname): setattr(self, funcname, partial(process, option))
def _mixin_setup(self): group = self.output_options_group = optparse.OptionGroup( self, "Output Options", "Configure your preferred output format") self.add_option_group(group) group.add_option( '--raw-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command in ' 'raw python form, this is suitable for re-reading the ' 'output into an executing python script with eval.'.format( self.get_prog_name()))) group.add_option( '--yaml-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command in ' 'yaml.'.format(self.get_prog_name()))) group.add_option( '--json-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command in ' 'json.'.format(self.get_prog_name()))) if self._include_text_out_: group.add_option( '--text-out', default=False, action='store_true', help=('DEPRECATED. Print the output from the \'{0}\' command ' 'in the same form the shell would.'.format( self.get_prog_name()))) outputters = loader.outputters( config.minion_config(None, check_dns=False)) group.add_option( '--out', '--output', dest='output', choices=outputters.keys(), help=('Print the output from the \'{0}\' command using the ' 'specified outputter. One of {1}.'.format( self.get_prog_name(), ', '.join([repr(k) for k in outputters])))) group.add_option( '--out-indent', '--output-indent', dest='output_indent', default=None, type=int, help=('Print the output indented by the provided value in spaces. ' 'Negative values disables indentation. Only applicable in ' 'outputters that support indentation.')) group.add_option('--no-color', default=False, action='store_true', help='Disable all colored output') for option in self.output_options_group.option_list: def process(opt): default = self.defaults.get(opt.dest) if getattr(self.options, opt.dest, default) is False: return if opt.dest not in ('out', 'output_indent', 'no_color'): if version.__version_info__ >= (0, 12): # XXX: CLEAN THIS CODE WHEN 0.13 is about to come out self.error('The option {0} was deprecated. Please use ' '\'--out {1}\' instead.'.format( opt.get_opt_string(), opt.dest.split('_', 1)[0])) self.selected_output_option = opt.dest funcname = 'process_{0}'.format(option.dest) if not hasattr(self, funcname): setattr(self, funcname, partial(process, option))