Skip to content

Commit

Permalink
Enhance logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Novotný committed Mar 27, 2021
1 parent 27138a4 commit 29eed9b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ GENERATED TEST:
TestRequest()
.set(.baseURL("https://api.github.com"))
.set(.path("/users/defunkt"))
.rx
.makeRequest()
.makeRxRequest()
.mapTo(TestRequest.Response.self)
.do(onSuccess: { _ in expectation.fulfill() })
.discardableSubscribe()
Expand Down
14 changes: 10 additions & 4 deletions curl2swift/parse_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
from ast import literal_eval
import sys
from urllib.parse import urlparse
import logging
from curl2swift.logger import logging
from curl2swift.parse_context import parse_context

ParsedContent = namedtuple('ParsedContent', 'request_name, description, url, method, path, query_params, headers, header_names, param_names, path_param_rows')


def parse_content(parser):
logging.info('Parsing content')
test_curl = "curl -i https://api.github.com/users/defunkt"

logging.info('Reading curl from clipboard')
curl = pyp3rclip.paste()
curl = curl.replace('--location', '')
curl = curl.replace('-v', '')
curl = curl.replace('--request', '-X')
curl = curl.replace('\\\n', '')
logging.info('cURL after cleanup: ' + curl)

try:
logging.info('Parsing cURL')
context = parse_context(curl, parser)
except:
logging.error('Parsing failed')
logging.error('Parsing failed (see usage above)')
logging.info('Falling back to test cURL')
curl = test_curl
context = parse_context(test_curl, parser)

logging.info('Transforming cURL to Python request object')
path_param_rows = []
param_names = []
method = context.method
Expand All @@ -52,7 +57,7 @@ def parse_content(parser):
try:
request_name = args[0]
except IndexError:
logging.error("Request name missing.")
logging.warning("Request name missing.")
request_name = 'Test'

try:
Expand All @@ -71,4 +76,5 @@ def parse_content(parser):
logging.info('Found body params: ' + str(param_names))

content = ParsedContent(request_name, description, url, method, path, query_params, headers, header_names, param_names, path_param_rows)
logging.warning("Content parsed.")
return curl, content
2 changes: 2 additions & 0 deletions curl2swift/process_request_template.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from curl2swift.logger import logging
import subprocess

from curl2swift.parse_content import ParsedContent
Expand All @@ -8,6 +9,7 @@


def process_request_template(content: ParsedContent, header_rows, body_param_rows, response_model):
logging.info('Processing request template')
two_level_indent_sep = '\n '
processed_template = REQUEST_TEMPLATE
processed_template = processed_template.replace('<REQUEST_NAME>', content.request_name)
Expand Down
2 changes: 2 additions & 0 deletions curl2swift/process_test_template.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from curl2swift.logger import logging
import re
from curl2swift.templates import *
from curl2swift.pprint_color import pprint_color
import subprocess


def process_test_template(header_rows, body_param_rows, content):
logging.info('Processing unit test templacte')
header_setters = []
for index, header in enumerate(content.headers):
value = content.headers[header]
Expand Down
3 changes: 1 addition & 2 deletions curl2swift/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
.set(.path("<PATH>"))
<HEADER_SETTERS>
<BODY_PARAM_SETTERS>
.rx
.makeRequest()
.makeRxRequest()
.mapTo(<REQUEST_NAME>Request.Response.self)
.do(onSuccess: { _ in expectation.fulfill() },
onError: { _ in XCTFail("The request should succeed") })
Expand Down

0 comments on commit 29eed9b

Please sign in to comment.