<s> from __future__ import print_function <EOL> import abc <EOL> import six <EOL> import logging <EOL> from st2client . formatters import doc <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class Branch ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , description , app , subparsers , parent_parser = None ) : <EOL> self . name = name <EOL> self . description = description <EOL> self . app = app <EOL> self . parent_parser = parent_parser <EOL> self . parser = subparsers . add_parser ( self . name , <EOL> description = self . description , <EOL> help = self . description ) <EOL> self . commands = dict ( ) <EOL> @ six . add_metaclass ( abc . ABCMeta ) <EOL> class Command ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , description , app , subparsers , <EOL> parent_parser = None , add_help = True ) : <EOL> self . name = name <EOL> self . description = description <EOL> self . app = app <EOL> self . parent_parser = parent_parser <EOL> self . parser = subparsers . add_parser ( self . name , <EOL> description = self . description , <EOL> help = self . description , <EOL> add_help = add_help ) <EOL> self . parser . set_defaults ( func = self . run_and_print ) <EOL> @ abc . abstractmethod <EOL> def run ( self , args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> @ abc . abstractmethod <EOL> def run_and_print ( self , args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def format_output ( self , subject , formatter , * args , ** kwargs ) : <EOL> json = kwargs . get ( '<STR_LIT>' , False ) <EOL> func = doc . Json . format if json else formatter . format <EOL> return func ( subject , * args , ** kwargs ) <EOL> def print_output ( self , subject , formatter , * args , ** kwargs ) : <EOL> if subject : <EOL> output = self . format_output ( subject , formatter , * args , ** kwargs ) <EOL> print ( output ) <EOL> else : <EOL> print ( '<STR_LIT>' ) </s>
