Esempio n. 1
0
)


# First define the parser
class CustomParser(Cmd2ArgumentParser):
    """Overrides error class"""
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

    def error(self, message: str) -> None:
        """Custom override that applies custom formatting to the error message"""
        lines = message.split('\n')
        linum = 0
        formatted_message = ''
        for line in lines:
            if linum == 0:
                formatted_message = 'Error: ' + line
            else:
                formatted_message += '\n       ' + line
            linum += 1

        self.print_usage(sys.stderr)

        # Format errors with style_warning()
        formatted_message = ansi.style_warning(formatted_message)
        self.exit(2, '{}\n\n'.format(formatted_message))


# Now set the default parser for a cmd2 app
set_default_argument_parser(CustomParser)
Esempio n. 2
0
            # hidden
            # action is triggered only when meet the parameter
            # merge_pcap = parser.add_argument("--" + name + "_protocol",
            #     action=partial(MergePcaps, prefix=name, protocol=protocol),
            #     help=argparse.SUPPRESS)
            # merge_pcap.default = "TEST"
        else:
            # TODO check for Preload
            # TODO set action to str if there is no Preload flag ?!
            load_action = parser.add_pcap(df_name, )

            # TODO enforce a protocol !!
            protocol = mp.Protocol.MPTCP if bitfield & PreprocessingActions.FilterMpTcpStream else mp.Protocol.TCP
            # preload=action_1,
            parser.filter_stream(
                df_name + 'stream', protocol=protocol, action=retain_stream(df_name,),
                choices_function=partial(stream_choices, protocol=protocol, df_name=df_name, action=load_action))

        if bitfield & PreprocessingActions.FilterDestination or direction:
            parser.filter_destination(dest=df_name + "_destinations")


        # TODO add as an action
        if skip_subflows:
            parser.skip_subflow(dest=df_name + "skipped_subflows", df_name=df_name)

    return parser


cmd2.set_default_argument_parser(MpTcpAnalyzerParser)