2019-07-31 05:10:28 +00:00
|
|
|
import sys
|
|
|
|
from difflib import SequenceMatcher
|
|
|
|
import logger
|
|
|
|
from . import arguments
|
|
|
|
|
2019-12-19 10:32:40 +00:00
|
|
|
|
2019-08-29 22:17:47 +00:00
|
|
|
def recommend(print_default: bool = True):
|
2019-07-31 05:10:28 +00:00
|
|
|
tried = sys.argv[1]
|
|
|
|
args = arguments.get_arguments()
|
|
|
|
print_message = 'Command not found:'
|
|
|
|
for key in args.keys():
|
|
|
|
for word in key:
|
|
|
|
if SequenceMatcher(None, tried, word).ratio() >= 0.75:
|
2019-12-19 10:32:40 +00:00
|
|
|
logger.warn(f'{print_message} "{tried}", '
|
|
|
|
+ 'did you mean "{word}"?',
|
|
|
|
terminal=True)
|
2019-07-31 05:10:28 +00:00
|
|
|
return
|
2019-12-19 10:32:40 +00:00
|
|
|
if print_default: logger.error('%s "%s"' %
|
|
|
|
(print_message, tried), terminal=True)
|