-
-
Notifications
You must be signed in to change notification settings - Fork 534
Baby step: Allow no keywords on the command line, and introduce -h, --help option #109
Conversation
All the machinery is almost there, just need to flip the switch. Instead of printing the help text when there's is no argument, we now support the standard -h, --help option, and a command line with no argument leads us into the REPL immediately. Transcript of a sample session: > googler -C -w github.com -n 3 Please initiate a query. googler (? for help): f Initiate a query first. googler (? for help): n Initiate a query first. googler (? for help): o Initiate a query first. googler (? for help): googler 1 GitHub - jarun/googler: Google from the command-line https://github.com/jarun/googler Google from the command-line. Contribute to googler development by creating an account on GitHub. 2 googler/googler.1 at master · jarun/googler · GitHub https://github.com/jarun/googler/blob/master/googler.1 Google from the command-line. Contribute to googler development by creating an account on GitHub. 3 googler/README.md at master · jarun/googler · GitHub https://github.com/jarun/googler/blob/master/README.md Google from the command-line. Contribute to googler development by creating an account on GitHub. googler (? for help): q Also fixed a bug in GooglerArgumentParser where file is not being defaulted to sys.stderr.
Damn, really hope we have some sort auto-generation mechanism for the man page. |
Grapse helps to some extent. |
Thank you! |
The demo seems to be in |
Or should we switch to mdoc? AFAIK mdoc is certainly more pleasant than |
Actually, although I had no luck with http://www.roperzh.com/grapse/, live preview for man pages is a very good idea. I'll hack up something this weekend. The idea is very simple, and is easily done with a bit of Python/Shell and a bit of JavaScript:
And https://github.com/joeyespo/grip can be used as an example. |
Hmmm... That's a problem. I never tested with I gifted them their first bug and we'll wait for a while on this :). |
They don't support |
Ahh, just saw their readme. |
This should work for you (OS X only): http://sveinbjorn.org/mandrake |
I'm going through mdoc. |
Looks nice, but that also seems to be a mdoc editor. At least it won't render our man page. |
|
👍 |
I think you should create a new project and share this with the world. ;) |
Exactly what I had in mind. But in reality it would be something trivial, like a single Python script. |
Yes, but it's better that one person writes it than everyone writing it. |
BTW, quick question because I didn't reach there yet (and donno where it is): If we move to mdoc with the command:
work? Or we need to invoke something else? |
It should work, but need to double check on Linux. At least the official FreeBSD man pages are in mdoc AFAIK, and OS X being close to FreeBSD also has a lot of mdoc man pages too. You can check the man page of BSD tar on Linux if you have time: https://gist.github.com/anonymous/ea1f802fa997f9d7fb707ec8f57145fa. I don't want to spin up a Linux box at the moment.
Yeah, what I meant to say is that it's somewhat more subtable for a gist... I'll throw what I have here in case you're interested. Apparently it's not integrated and have rendering problems for now, but I'll polish when I have time.
#!/usr/bin/env python3
import sys
import textwrap
def to_html(ms):
length = len(ms)
ms += chr(0) * 2
bs = chr(8)
hs = textwrap.dedent("""
<!DOCTYPE html>
<head>
<title>man page</title>
</head>
<body>
<div style="width: 846px; margin: auto">
<pre>
""")
inbold = False
inunderline = False
i = 0
while i < length:
# TODO: Both bold and underline
ch = ms[i]
if ms[i+1] == bs:
bold = (ch == ms[i+2])
underline = (ch == '_')
else:
bold = underline = False
if inbold and not bold:
hs += '</b>'
inbold = False
if inunderline and not underline:
hs += '</u>'
inunderline = False
if bold:
if not inbold:
hs += '<b>'
inbold = True
i += 2
if underline:
if not inunderline:
hs += '<u>'
inunderline = True
ch = ms[i+2]
i += 2
if ch == '<':
hs += '<'
elif ch == '>':
hs += '>'
else:
hs += ch
i += 1
hs += textwrap.dedent("""
</pre>
</div>
</body>
""")
return hs
def main():
sys.stdout.write(to_html(sys.stdin.read()))
if __name__ == '__main__':
main() Then > COLUMNS=120 PAGER=cat man ~/dev/src/forks/googler/googler.1 </dev/null | ./previewman | browser |
👍 |
Will confirm in the evening. |
As you can see, text processing in Python... Such a shame. But I'm not a Perl wizard, and even worse at Awk, so that's it, a poorly performing piece of crap that somehow does the job (almost). |
I think in a combat it's better to use familiar weapons than suicide with brand new ones (without proper training). |
Just checked. Works fine. |
I found this one as well: ronn |
Knew that one, not impressed. I once tried all Markdown to man (groff) converters on the market and was very disappointed by the quality (not sure if the quality of stuff have since improved). Among lightweight markup languages I only know AsciiDoc (or rather, the implementation |
asciidoc looks good too. I can try this out. Anything that makes life easier with man pages. |
This is point 4 of #87 (comment).
All the machinery is almost there, just need to flip the switch.
Instead of printing the help text when there's is no argument, we now support the standard
-h, --help
option, and a command line with no argument leads us into the REPL immediately.Transcript of a sample session:
Also fixed a bug in
GooglerArgumentParser
where file is not being defaulted tosys.stderr
.