<s> import six <EOL> from jirafs import utils <EOL> from jirafs . plugin import CommandPlugin <EOL> from jirafs . utils import run_command_method_with_kwargs <EOL> class Command ( CommandPlugin ) : <EOL> """<STR_LIT>""" <EOL> MIN_VERSION = '<STR_LIT>' <EOL> MAX_VERSION = '<STR_LIT>' <EOL> AUTOMATICALLY_INSTANTIATE_FOLDER = False <EOL> FIELDS = ( <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT:description>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> ) <EOL> def set_field_value ( self , data , field , value ) : <EOL> starting_reference = data <EOL> path = field . get ( '<STR_LIT:path>' , field [ '<STR_LIT:name>' ] ) <EOL> for part in path . split ( '<STR_LIT:.>' ) : <EOL> if part not in data : <EOL> data [ part ] = { } <EOL> last_reference = data <EOL> data = data [ part ] <EOL> last_reference [ path . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] ] = value <EOL> return starting_reference <EOL> def prompt_for_input ( self , field ) : <EOL> while True : <EOL> if field . get ( '<STR_LIT:default>' ) : <EOL> value = raw_input ( '<STR_LIT>' % ( <EOL> field . get ( '<STR_LIT>' ) , <EOL> field . get ( '<STR_LIT:default>' ) , <EOL> ) ) <EOL> else : <EOL> value = raw_input ( '<STR_LIT>' % ( <EOL> field . get ( '<STR_LIT>' ) <EOL> ) ) <EOL> value = value . strip ( ) <EOL> if value : <EOL> return value <EOL> elif not field . get ( '<STR_LIT>' ) and field . get ( '<STR_LIT:default>' ) : <EOL> return field . get ( '<STR_LIT:default>' ) <EOL> elif not field . get ( '<STR_LIT>' ) : <EOL> return value <EOL> def main ( self , args , jira , path , parser , ** kwargs ) : <EOL> server = args . server <EOL> if not server : <EOL> server = utils . get_default_jira_server ( ) <EOL> issue_data = { } <EOL> for field in self . FIELDS : <EOL> if getattr ( args , field [ '<STR_LIT:name>' ] ) is not None : <EOL> self . set_field_value ( <EOL> issue_data , field , getattr ( args , field [ '<STR_LIT:name>' ] ) <EOL> ) <EOL> elif args . quiet : <EOL> self . set_field_value ( issue_data , field , field . get ( '<STR_LIT:default>' ) ) <EOL> else : <EOL> self . set_field_value ( <EOL> issue_data , <EOL> field , <EOL> self . prompt_for_input ( field ) <EOL> ) <EOL> jira_client = jira ( server ) <EOL> issue = jira_client . create_issue ( issue_data ) <EOL> return run_command_method_with_kwargs ( <EOL> '<STR_LIT>' , <EOL> path = None , <EOL> url = issue . permalink ( ) , <EOL> jira = jira , <EOL> ) <EOL> def add_arguments ( self , parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , default = None ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' <EOL> ) <EOL> for argument in self . FIELDS : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' % argument [ '<STR_LIT:name>' ] , <EOL> default = None , <EOL> type = six . text_type <EOL> ) </s>
