Adding some style guidelines for help on CLI commands
Pages: 1 2
Paolo Fabio Zaino (28) 1882 posts |
Hi everyone, This has triggered some side questions on the fact that, while RISC OS Modules have a fairly well defined standardisation on the matter of providing some form of help on syntax and usage to the user, for external CLI tools there seems nothing being defined (or at least I couldn’t find anything formal). If there is any standardisation for such matter can someone please pin-point me at it thanks! If not then would it be ok to formalise a similar approach as Linux/BSD have developed through the years? All thoughts welcome, but please let’s try to stay on topic, pleaseeee :) |
Paolo Fabio Zaino (28) 1882 posts |
For who is not familiar with the Linux/BSD approach here is a simple example: To request help for a command:
Help general output:
|
Steve Pampling (1551) 8170 posts |
The -h or -help switch/option format is:
No one should have any issues if you do something for CLI that matches long-standing OS CLI elements |
Paolo Fabio Zaino (28) 1882 posts |
Thanks Steve! So we want -h and -help (always single dash) instead of (single dash)h and (double dash)help (for the extended form of the option/switch name). |
Paolo Fabio Zaino (28) 1882 posts |
@ DavidS
Not sure what you mean on that comment… For modules the help is provided through the help command itself, so syntax is totally different: help {command-name} And the output format is very minimalistic because the description is displayed when typing help ModuleName. so the only thing I can re-use from the help for modules are the symbols used in syntax description. And finally there is no {ref} section on the original help for modules. |
Rick Murray (539) 13840 posts |
On RISC OS, commands typically work in two ways. The first, as in the case of many of the built in commands, the parameters are in a fixed order so are just given: *Copy This That and if there’s an option string, it goes at the end. It cannot go anywhere else. The typical response to running the command with no input is: Syntax: <command name> <options> For example: Syntax: a8time <input> [<output>] Syntax: *Copy <source spec> <destination spec> [<options>] For more complex things, often taking parameters which aren’t necessarily in any particular order or too many choices to fix which parameter is which, the syntax is like: *Wotsit -name param1 -othername param2 Often (but not always) parameters can be shortened down to one letter. People expect at least “-h” to give help. Examples here are jpegtran, infodump, cc, link and dozens of other things.
Please:
I would say that it might be useful to add a single line at the top of the general help output saying what the program is and its version. Refer to cc, link, and objasm for examples. Just my €0,02 but there are plenty of examples within RISC OS of how command line tools ‘usually’ handle their input. |
Steve Pampling (1551) 8170 posts |
Check the existing commands, but I can’t recall having to use double-dash on RO (I could have been missing something though) |
Paolo Fabio Zaino (28) 1882 posts |
Thanks Rick,
no worries, all my code is always native supporting RISC OS file-naming conventions etc, but thanks for the reminder! |
Steve Pampling (1551) 8170 posts |
That said, most RO users would expect that
was going to reel out the base help for Wotsit and that
would give you help on the flavour of Wotsit. (A little nuance lost on non-Brits) |
Paolo Fabio Zaino (28) 1882 posts |
@ Rick JFYI ObjAsm accepts double dashes, however it makes no differences between single dash for short form and double for extended form. Just wanted to point this out for correctness. I can quickly extend my parser to do the same, not a biggie. Anyway this topics is about deciding together what we would like to have as a standard, so all good feedback so far, thanks a lot everyone! :) |
Steve Fryatt (216) 2105 posts |
That should always be the case, as it’s how Use
Double-dash is a pragmatic solution to the problem of deciding whether RISC OS doesn’t have that “problem”, because
That’s purely to allow things to fall out of the Autobuilder without needing their filename handling code to be changed. If something expects |
Paolo Fabio Zaino (28) 1882 posts |
@ Steve That said, most RO users would expect that Of course, but as I reminded to DavidS, the help {command-name} or h. {command-name} are for internal commands provided by modules. Such help standards are well documented in the PRM and are not part of my question. The problem with external commands is they can’t use the “help” facility offered by RISC OS to modules, hence the need for a standard way to make it easy to get help for external commands. Also, little side note, the old RISC OS “help” comes from Acorn MOS and so never really had a {ref} (reference section) which could present URLs for more details or updates etc… (and the reasons for this are obvious lol it was defined before the Internet revolution). When we all agree on the format, someone with forum super-powers could create a page on here with the details to help everyone coding external commands in a way that makes it easy for users to understand how they work. Makes sense? |
Stuart Swales (1481) 351 posts |
OS_ReadArgs. It’s why we put it in there. |
Paolo Fabio Zaino (28) 1882 posts |
@ Steve Fryatt Thanks
there is also the issue with the [space] characters actually, bash for example splits switches based on the space so, something like: -o {destination-file} requires a little help depending on the language used. But again not a problem on RISC OS. @ everyone However on RISC OS we have the old Acorn MOS switches, which may need some attention: copy {source} {destination} ~C F Do we want to keep them or just leave them to the very very old commands? |
Alan Adams (2486) 1149 posts |
How about extending the help system – for “help fred” if the answer isn’t found in a module, try “fred -h” and send the results back to the user?
and as i highlighted in another thread today, that’s the same as “copy {source} {destination} ~CF” |
Paolo Fabio Zaino (28) 1882 posts |
@ Alan thanks for your feedback
I am good with that as it would establish a full standard approach across all the various commands. Hopefully no one has an issue with it.
Yup, so the questions for everyone are:
|
Rick Murray (539) 13840 posts |
+1
Does anything other than Copy/Count/Wipe use this format? I’d suggest leaving the ~FLAG~S syntax to Copy/Count/Wipe as a historical anomaly (one of many). |
Stuart Swales (1481) 351 posts |
Also +1. Nothing other than Copy/Count/Wipe should use that format. Historical. Enumerate anything else. Note that ~CG != ~C ~G |
Paolo Fabio Zaino (28) 1882 posts |
All right, Next steps:
For the C template that’s what I have got coded and tested so far: C parser that:
The show_help function is pre-implemented and uses the same struct to display help so the developer only needs to instantiate the struct and populate it with whatever he/she wants (and obviously include the library). Obviously the C parser compiles fine with DDE latest, needs to test with previous releases. How’s that sound? |
Paolo Fabio Zaino (28) 1882 posts |
@ Stuart
Thanks for noting it I corrected the example. My question/statement was more in terms of parsing like “~C ~G” != “~C~G” for the parser because of the absence of the space in between them, but given that we do not want to use the old “~” I think we’re good :) |
Chris Johns (8262) 242 posts |
I remember years ago our school IT guy wanted to know the options for DELTREE in DOS, so he typed it with no parameters expecting it to reply with a usage: type message. He thought it was taking a long time to do so while it thrashed the drive, until it dawned on him what it was doing. He was in the root of the C: drive too. Could *Help be extended to – if it’s not recognised by a built-in command – either look for a help file to display (either relative to the command, with different path or something else), or to run the command with -help. |
Chris Hall (132) 3554 posts |
MSDOS/Windows is a careful combination of the clever and the stupid. I typed ‘C>format’ and it was intelligent enough to know that c: was a fixed disc so knew it did not have to ask ‘Format drive a: (Y/N??’ and it therefore said ‘press any key to format drive C’. After a little debate with myself whether CTRL-C would abort it, I simply unplugged the computer. |
Paolo Fabio Zaino (28) 1882 posts |
thanks for your feedback guys. So on the matter of “just run the command without parameters to get the help”. I am not so sure if it’s a safe practice tbh (but I am happy with whatever the majority will want). The reason I mention this is because there can be (albeit few) commands that do not requires parameters and so in those cases the requirement may collide. For instance some typical examples (also on other OS): halt or clear Now while commands like clear aren’t that dangerous, halt will halt the system on a linux box and if executed as root won’t even ask for confirmation. So maybe the “-h” is probably generally safer. For what concern the extension of the RISC OS help command please read the last post on the first page of this topic. Just my 0.5c |
Charles Ferguson (8243) 427 posts |
The standard way to get help on a command is to use *Help. Obviously commands may offer their own help, but the standard interface to get help on the commands has existed since the BBC (yeah, I’m pretty sure that the BBC was the first system to offer the extensions to the help interface through the service system). It’s referenced in http://www.riscos.com/support/developers/riscos6/index.html but seemingly the actual text was never HTML’d. The full text is in the archive of the contents which I’ve just downloaded from http://www.riscos.com/support/developers/riscos6/selectprm-text.zip and explains the manner in which such commands are documented and how they can be extended. As for the options which commands take, the form supported by OS_ReadArgs is the expected form for users. The options format used by *Copy, *Wipe, *Count should be considered an aberation to that; it’s ugly, complicated to parse and pretty much nobody ever gets the usage right on the command line in the face of the Copy$Options, etc variables. Regarding providing additional information in addition to the command line switches, *Help is always executed with paging mode enabled, so it is quite possible to provide more copious information. bq. How about extending the help system – for “help fred” if the answer isn’t found in a module, try “fred -h” and send the results back to the user? This is unworkable because `*Help` is expected to not affect the application that is running. Because there is a lack of sub-processes you cannot assume that you can run any command line command from within *Help. Not only do you not have a guaranteed application space in which to run, it is not possible to guarantee that the system had ANY environment that could handle being replaced and restored. That’s before you consider that entering an application requires flattening the SVC stack (or preserving it and restoring later… an even more daunting prospect). Whilst unwise, within RISC OS it would be safe to redirect output with OS_ChangeRedirection and issue a *Help command within a CallBack, capturing the output for your own use. The conditions under which *Help can be issued could be tightened up, but to do so just to allow you to run commands to get help would be… overkill. Thus it is a complete no-go to execute application (or other kind of *Command) at all when *Help is issued. |
Steve Pampling (1551) 8170 posts |
At that point you pause and ask yourself “did that happen on both sides of the fence?” However, if we are trying to establish standard behaviour then rectifying any disparity is usually useful. |
Pages: 1 2