Skip to content

Commit

Permalink
fix: translation of object to JSON only when we are in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ha36d authored and Hamed Faramarzi committed Oct 24, 2021
1 parent d7bd151 commit e818bb2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions nirjas/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LanguageMapper:
'.php': 'php',
'.pl': 'perl',
'.r': 'r',
'.R':'r',
'.R': 'r',
'.rb': 'ruby',
'.rs': 'rust',
'.sh': 'shell',
Expand All @@ -82,7 +82,7 @@ class LanguageMapper:
'.lic': 'text',
'.install': 'text',
'.OSS': 'text',
'.gl': 'text'
'.gl': 'text',
}

@staticmethod
Expand Down Expand Up @@ -121,7 +121,7 @@ def run_cli():
out_file = args.outFile
try:
if file is not None:
return file_runner(file)
return file_runner(file, 'json')
return inputfile_runner(inputfile, out_file)
except NotSupportedExtension as e:
print(e, file=os.sys.stderr)
Expand All @@ -140,7 +140,8 @@ def scan_the_file(file):
func = langname + '.' + langname + 'Extractor'
return eval(func)(file)

def file_runner(file):

def file_runner(file, type='dictionary'):
'''
Check if the input is a file or a directory and iterate with
scan_the_file()
Expand All @@ -161,7 +162,8 @@ def file_runner(file):
result.append(scan_the_file(file_to_scan).get_dict())
except Exception:
continue
result = json.dumps(result, sort_keys=False, indent=4)
if type == 'json':
return json.dumps(result, sort_keys=False, indent=4)
return result


Expand Down

0 comments on commit e818bb2

Please sign in to comment.