#NEWLINE# @ click . command ( help = 'Fetch a document from the given URL.' ) #NEWLINE# @ click . argument ( 'url' ) #NEWLINE# @ click . option ( '--debug' , '-d' , is_flag = True , help = 'Display the request/response' ) #NEWLINE# @ click . option ( '--format' , default = None , type = click . Choice ( [ 'corejson' , 'hal' , 'hyperschema' , 'openapi' ] ) ) #NEWLINE# def get( url , debug , format ) : #NEWLINE# #INDENT# if format : #NEWLINE# #INDENT# decoder = { #NEWLINE# #INDENT# 'corejson' : coreapi . codecs . CoreJSONCodec ( ) , #NEWLINE# 'hal' : coreapi . codecs . HALCodec ( ) , #NEWLINE# 'hyperschema' : coreapi . codecs . HyperschemaCodec ( ) , #NEWLINE# 'openapi' : coreapi . codecs . OpenAPICodec ( ) , #NEWLINE# #UNINDENT# } [ format ] #NEWLINE# decoders = [ decoder ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# decoders = None #NEWLINE# #UNINDENT# client = get_client ( decoders = decoders , debug = debug ) #NEWLINE# history = get_history ( ) #NEWLINE# try : #NEWLINE# #INDENT# doc = client . get ( url ) #NEWLINE# #UNINDENT# except coreapi . exceptions . ErrorMessage as exc : #NEWLINE# #INDENT# click . echo ( display ( exc . error ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# click . echo ( display ( doc ) ) #NEWLINE# if isinstance ( doc , coreapi . Document ) : #NEWLINE# #INDENT# history = history . add ( doc ) #NEWLINE# set_document ( format ) #NEWLINE# set_history ( history )