Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: cs@zip.com.au Newsgroups: comp.lang.python Subject: Re: What should Python apps do when asked to show help? Date: Sun, 1 May 2016 10:06:28 +1000 Lines: 113 Message-ID: References: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> <20160501000628.GA56167@cskk.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de 8zP01i5iuBSoY7eD4kMDqgFX2y7ehmpofTJyjSHEmB6A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'subject:Python': 0.05; 'url:bitbucket': 0.05; 'escape': 0.07; 'file)': 0.07; 'imply': 0.07; 'subject:help': 0.07; 'bold': 0.09; 'implies': 0.09; 'linux/unix': 0.09; 'literal': 0.09; 'stdout': 0.09; 'tune': 0.09; 'output': 0.13; 'intermediate': 0.15; 'options.': 0.15; 'thu,': 0.15; '"see': 0.16; '"to': 0.16; '(given': 0.16; '(regardless': 0.16; '--help': 0.16; '-h/--help': 0.16; '2016': 0.16; '>on': 0.16; '>that': 0.16; 'backspace': 0.16; 'characters:': 0.16; 'col': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'macro': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'outputs': 0.16; 'possibly,': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:io': 0.16; 'received:optusnet.com.au': 0.16; 'received:psf.io': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'skip:> 20': 0.16; 'subject:show': 0.16; 'subject:when': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; '>>>': 0.20; '(the': 0.22; 'fairly': 0.22; 'saying': 0.22; 'platform,': 0.22; 'users,': 0.22; 'cheers,': 0.22; 'am,': 0.23; '(or': 0.23; 'needed.': 0.23; 'tables': 0.23; 'this:': 0.23; 'plain': 0.24; 'unix': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; '(which': 0.26; 'followed': 0.27; 'fri,': 0.27; 'gnu': 0.27; 'actual': 0.28; 'accomplished': 0.29; 'cat': 0.29; 'obscure': 0.29; "i'm": 0.30; 'option': 0.31; 'core': 0.32; 'skip:_ 10': 0.32; 'run': 0.33; 'point': 0.33; "d'aprano": 0.33; 'received:com.au': 0.33; 'steven': 0.33; "i'll": 0.33; 'that,': 0.34; 'gets': 0.35; 'text': 0.35; 'displays': 0.35; 'skip:> 10': 0.35; 'text.': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'url:org': 0.36; 'tool': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'display': 0.37; 'say': 0.37; 'charset:us- ascii': 0.37; 'wanted': 0.37; 'things': 0.38; 'doing': 0.38; 'itself': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'goes': 0.39; 'format': 0.39; 'whatever': 0.39; 'does': 0.39; 'application': 0.39; 'enough': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'easy': 0.60; 'from:no real name:2**0': 0.60; 'your': 0.60; "you'll": 0.61; 'default': 0.61; 'skip:n 10': 0.62; 'more': 0.63; 'here:': 0.63; 'cameron': 0.66; 'capture': 0.66; 'choose': 0.68; 'friendly': 0.74; '(actually,': 0.84; 'compose': 0.84; 'edwards': 0.91 Content-Disposition: inline In-Reply-To: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=EfU1O6SC c=1 sm=1 tr=0 a=kPLexIa+XrsL4mdc8kxeNA==:117 a=kPLexIa+XrsL4mdc8kxeNA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=yrkiwgmsf1kA:10 a=kZ7UWmmPAAAA:8 a=ZLGELXoPAAAA:8 a=xtERp6CFAAAA:8 a=vrnE16BAAAAA:8 a=iVsNPBlKs3tFafcaZYAA:9 a=CjuIK1q_8ugA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20160501000628.GA56167@cskk.homeip.net> X-Mailman-Original-References: <5722bb82$0$1600$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:107928 On 29Apr2016 11:40, Steven D'Aprano wrote: >On Fri, 29 Apr 2016 07:08 am, Grant Edwards wrote: >> On 2016-04-28, Random832 wrote: >>> On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: >>>> That's fine. If you want two or three forms of documentation then you >>>> prepare two or three forms of documentation. >>>> >>>> Adding an option to run the default 'help' output through a pager or >>>> display it in a web browser doesn't somehow force you "to compose two >>>> forms of documentation" unless you want two forms of documentation. >>> >>> The point is that having "help" output at all (beyond either a cursory >>> "see the manpage") implies two forms of documentation (given you already >>> have a manpage), and some people choose not to do that, instead >>> launching directly into the manpage (which implies using a pager) >> >> But I'm saying that having --help output the manpage should not imply >> using a pager. > > >What manpage? I don't have a manpage. The only help my application has is >whatever it outputs (which it gets from its docstring). > >What is a good place where I can find out more about writing manpages? "man 5 man"? Describes the internal format of man pages (the [ntg]roff -man macro set). Many people use an intermediate more human friendly format and use a tool to transcribe -man format text. For standalone things I find Perl's "POD" format fairly easy to use (the pod2man tool itself does have shortcomings though). >> If --help is going to output the manpage, then I'm saying it can (and >> should) be written to stdout without use of pager (and it shouldn't >> have escape sequences or backspaces in it either). The Unix way is >> that the output from whatever --help should be plain text written to >> stdout (regardless of length). > >Agree. The -h/--help option will output plain text to stdout. Yay. >> If you want to output the man page, this can be accomplished simply by >> doing someting like: >> os.environ["GROFF_NO_SGR"] = "1"; >> os.system("man -Tascii mycmd | col -bx"); > >That doesn't work for me: >[steve@ando ~]$ man -Tasciii rm >man: invalid option -- T Yes, it is nonportable. Presumes groff possibly, and GNU "man". >However, this almost works: > >man -Pcat rm > >appears to output unformatted, plain text to stdout. As should: man rm | cat without obscure options. >However, if you capture >the output (say, to a file) you'll see it is full of backspaces, e.g.: > >N^HNA^HAM^HME^HE > rm - remove files or directories > >S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS > r^Hrm^Hm [_^HO_^HP_^HT_^HI_^HO_^HN]... _^HF_^HI_^HL_^HE... Yes. >instead of > >NAME > rm - remove files or directories [...] > >Apparently `less` understands overstriking and displays it as bold (or >underlining in the case of _^H. That's very clever, but how do I get actual >plain text out of `man` without the backspaces? That is what Grant Edwards' "col -bx" does. (Actually, col can do more, because tables also do funky things; let us not go there.) But removing the overstriking is pretty easy even without col. My "unbs" script does it, and its core operation is this: s/[^^H]^H//g Those ^Hs are literal backspace characters: remove any non-backspace followed by a backspace. Full script here: https://bitbucket.org/cameron_simpson/css/src/tip/bin/unbs >> If I want the --help output run through a pager, I'll do it myself. > >Easy enough to say for Linux/Unix users, but there are those who might not >have a pager that is easy to use, or at all. pydoc goes to considerable >trouble to work out the best pager available for your platform, falling >back to its own if needed. To use that is literally a two liner: > >import pydoc >pydoc.pager(HELPTEXT) Aye, but what is wanted by some of us is an easy incantation to tune that to plain old sys.stdout.write in some flavour. Cheers, Cameron Simpson