<s> import json <EOL> import click <EOL> import cligj <EOL> import mapbox <EOL> from mapboxcli . errors import MapboxCLIException <EOL> @ click . command ( short_help = "<STR_LIT>" ) <EOL> @ cligj . features_in_arg <EOL> @ click . option ( '<STR_LIT>' , default = "<STR_LIT>" , <EOL> type = click . Choice ( mapbox . Directions ( ) . valid_profiles ) , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , default = True , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , default = "<STR_LIT:text>" , <EOL> type = click . Choice ( mapbox . Directions ( ) . valid_instruction_formats ) , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , default = "<STR_LIT>" , <EOL> type = click . Choice ( mapbox . Directions ( ) . valid_geom_encoding ) , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , default = True , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT:->' , <EOL> help = "<STR_LIT>" ) <EOL> @ click . pass_context <EOL> def directions ( ctx , features , geojson , profile , alternatives , <EOL> instructions , geometry , steps , output ) : <EOL> """<STR_LIT>""" <EOL> stdout = click . open_file ( output , '<STR_LIT:w>' ) <EOL> access_token = ( ctx . obj and ctx . obj . get ( '<STR_LIT>' ) ) or None <EOL> if geojson : <EOL> geometry = '<STR_LIT>' <EOL> service = mapbox . Directions ( access_token = access_token ) <EOL> try : <EOL> res = service . directions ( <EOL> features , <EOL> steps = steps , <EOL> alternatives = alternatives , <EOL> instructions = instructions , <EOL> geometry = geometry , <EOL> profile = profile ) <EOL> except mapbox . errors . ValidationError as exc : <EOL> raise click . BadParameter ( str ( exc ) ) <EOL> if res . status_code == <NUM_LIT:200> : <EOL> if geojson : <EOL> click . echo ( json . dumps ( res . geojson ( ) ) , file = stdout ) <EOL> else : <EOL> click . echo ( res . text , file = stdout ) <EOL> else : <EOL> raise MapboxCLIException ( res . text . strip ( ) ) </s>
