mirror of
https://github.com/chubin/cheat.sh
synced 2024-11-10 05:24:13 +00:00
queries may contain spaces; first word is the section
This commit is contained in:
parent
63a716fdf7
commit
03bae9e5da
4 changed files with 30 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
server:
|
||||
address: "0.0.0.0"
|
||||
cache:
|
||||
type: none
|
||||
type: redis
|
||||
|
|
|
@ -47,6 +47,8 @@ class Question(UpstreamAdapter):
|
|||
self._output_format = "ansi"
|
||||
return UpstreamAdapter._get_page(self, topic, request_options=request_options)
|
||||
|
||||
topic = topic.replace('+', ' ')
|
||||
|
||||
# if there is a language name in the section name,
|
||||
# cut it off (de:python => python)
|
||||
if '/' in topic:
|
||||
|
|
|
@ -26,6 +26,17 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'):
|
|||
Additional request options specified in `request_options`.
|
||||
"""
|
||||
|
||||
def _add_section_name(query):
|
||||
# temporary solution before we don't find a fixed one
|
||||
if ' ' not in query and '+' not in query:
|
||||
return query
|
||||
if '/' in query:
|
||||
return query
|
||||
if ' ' in query:
|
||||
# for standalone queries only that may contain ' '
|
||||
return "%s/%s" % tuple(query.split(' ', 1))
|
||||
return "%s/%s" % tuple(query.split('+', 1))
|
||||
|
||||
def _rewrite_aliases(word):
|
||||
if word == ':bash.completion':
|
||||
return ':bash_completion'
|
||||
|
@ -74,6 +85,7 @@ def cheat_wrapper(query, request_options=None, output_format='ansi'):
|
|||
return topic, keyword, search_options
|
||||
|
||||
query = _sanitize_query(query)
|
||||
query = _add_section_name(query)
|
||||
query = _rewrite_aliases(query)
|
||||
query = _rewrite_section_name(query)
|
||||
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
Unknown topic.
|
||||
Do you mean one of these topics maybe?
|
||||
[38;5;246m# How do I copy a file in Python?[39m
|
||||
[38;5;246m# [39m
|
||||
[38;5;246m# shutil (http://docs.python.org/3/library/shutil.html) has many methods[39m
|
||||
[38;5;246m# you can use. One of which is:[39m
|
||||
|
||||
* python/:learn 69
|
||||
* python/Classes 67
|
||||
* python/Modules 67
|
||||
[38;5;70;01mfrom[39;00m[38;5;252m [39m[38;5;68;04mshutil[39;00m[38;5;252m [39m[38;5;70;01mimport[39;00m[38;5;252m [39m[38;5;252mcopyfile[39m
|
||||
|
||||
[38;5;252mcopyfile[39m[38;5;252m([39m[38;5;252msrc[39m[38;5;252m,[39m[38;5;252m [39m[38;5;252mdst[39m[38;5;252m)[39m
|
||||
|
||||
[38;5;246m# Copy the contents of the file named src to a file named dst. The[39m
|
||||
[38;5;246m# destination location must be writable; otherwise, an IOError exception[39m
|
||||
[38;5;246m# will be raised. If dst already exists, it will be replaced. Special[39m
|
||||
[38;5;246m# files such as character or block devices and pipes cannot be copied[39m
|
||||
[38;5;246m# with this function. src and dst are path names given as strings.[39m
|
||||
[38;5;246m# [39m
|
||||
[38;5;246m# [Swati] [so/q/123198] [cc by-sa 3.0][39m
|
||||
|
|
Loading…
Reference in a new issue