<s> import inspect <EOL> from gocd_cli . utils import dasherize_name <EOL> from gocd_cli . exceptions import MissingDocumentationError <EOL> class BaseCommand ( object ) : <EOL> @ classmethod <EOL> def _get_or_raise ( cls , attr , exception , message = None ) : <EOL> value = getattr ( cls , attr , None ) <EOL> if not value : <EOL> if not message : <EOL> message = '<STR_LIT>' . format ( cls . __name__ , attr ) <EOL> raise exception ( message ) <EOL> return value <EOL> @ classmethod <EOL> def get_usage ( cls ) : <EOL> usage = cls . _get_or_raise ( '<STR_LIT>' , MissingDocumentationError ) <EOL> return '<STR_LIT>' . format ( <EOL> call_documentation = cls . get_call_documentation ( ) , <EOL> usage_summary = cls . get_usage_summary ( ) , <EOL> usage = inspect . cleandoc ( usage ) , <EOL> ) <EOL> @ classmethod <EOL> def get_usage_summary ( cls ) : <EOL> return cls . _get_or_raise ( '<STR_LIT>' , MissingDocumentationError ) <EOL> @ classmethod <EOL> def get_call_documentation ( cls ) : <EOL> def get_arg_names ( ) : <EOL> args , varargs , keywords , defaults = inspect . getargspec ( cls . __init__ ) <EOL> if args [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> del args [ <NUM_LIT:0> ] <EOL> if args [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> del args [ <NUM_LIT:0> ] <EOL> kwargs = args [ - len ( defaults ) : ] if defaults else [ ] <EOL> positional = args [ : - len ( kwargs ) ] if kwargs else args <EOL> return positional , kwargs <EOL> args , kwargs = get_arg_names ( ) <EOL> return '<STR_LIT>' . format ( <EOL> command = dasherize_name ( cls . __name__ ) , <EOL> args = '<STR_LIT:U+0020>' . join ( '<STR_LIT>' . format ( arg ) for arg in args ) , <EOL> kwargs = '<STR_LIT:U+0020>' . join ( '<STR_LIT>' . format ( arg . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) ) for arg in kwargs ) , <EOL> ) . strip ( ) <EOL> def _return_value ( self , output , exit_code ) : <EOL> if isinstance ( exit_code , bool ) : <EOL> exit_code = <NUM_LIT:0> if exit_code else <NUM_LIT:2> <EOL> return dict ( <EOL> exit_code = exit_code , <EOL> output = output , <EOL> ) </s>
