Interactive help

From Rosetta Code
Revision as of 15:27, 12 February 2019 by PureFox (talk | contribs) (Added Go)
Interactive help is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Demonstrate any interactive (or command line) help offered by the language implementation.

This can be for exploring features or syntax, or perhaps a simple message on where to find more information.

Go

The 'go doc' command line tool shows documentation for either a package or a symbol within a package.

For example, here we list the exported functions and types in the 'strings' package in the standard library:

$ go doc strings
package strings // import "strings"

Package strings implements simple functions to manipulate UTF-8 encoded
strings.

For information about UTF-8 strings in Go, see
https://blog.golang.org/strings.

func Compare(a, b string) int
func Contains(s, substr string) bool
func ContainsAny(s, chars string) bool
func ContainsRune(s string, r rune) bool
func Count(s, substr string) int
func EqualFold(s, t string) bool
func Fields(s string) []string
func FieldsFunc(s string, f func(rune) bool) []string
func HasPrefix(s, prefix string) bool
func HasSuffix(s, suffix string) bool
func Index(s, substr string) int
func IndexAny(s, chars string) int
func IndexByte(s string, c byte) int
func IndexFunc(s string, f func(rune) bool) int
func IndexRune(s string, r rune) int
func Join(a []string, sep string) string
func LastIndex(s, substr string) int
func LastIndexAny(s, chars string) int
func LastIndexByte(s string, c byte) int
func LastIndexFunc(s string, f func(rune) bool) int
func Map(mapping func(rune) rune, s string) string
func Repeat(s string, count int) string
func Replace(s, old, new string, n int) string
func Split(s, sep string) []string
func SplitAfter(s, sep string) []string
func SplitAfterN(s, sep string, n int) []string
func SplitN(s, sep string, n int) []string
func Title(s string) string
func ToLower(s string) string
func ToLowerSpecial(c unicode.SpecialCase, s string) string
func ToTitle(s string) string
func ToTitleSpecial(c unicode.SpecialCase, s string) string
func ToUpper(s string) string
func ToUpperSpecial(c unicode.SpecialCase, s string) string
func Trim(s string, cutset string) string
func TrimFunc(s string, f func(rune) bool) string
func TrimLeft(s string, cutset string) string
func TrimLeftFunc(s string, f func(rune) bool) string
func TrimPrefix(s, prefix string) string
func TrimRight(s string, cutset string) string
func TrimRightFunc(s string, f func(rune) bool) string
func TrimSpace(s string) string
func TrimSuffix(s, suffix string) string
type Builder struct{ ... }
type Reader struct{ ... }
    func NewReader(s string) *Reader
type Replacer struct{ ... }
    func NewReplacer(oldnew ...string) *Replacer

BUG: The rule Title uses for word boundaries does not handle Unicode punctuation properly.

We can now 'dig down' to obtain the documentation for the TrimSpace function wthin the strings package:

$ go doc strings.TrimSpace
func TrimSpace(s string) string
    TrimSpace returns a slice of the string s, with all leading and trailing
    white space removed, as defined by Unicode.

and to list the methods of the strings.Replacer struct:

$ go doc strings.Replacer
type Replacer struct {
	// Has unexported fields.
}
    Replacer replaces a list of strings with replacements. It is safe for
    concurrent use by multiple goroutines.


func NewReplacer(oldnew ...string) *Replacer
func (r *Replacer) Replace(s string) string
func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)

Finally, we obtain the documentation for the strings.Replacer.WriteString method:

$ go doc strings.Replacer.WriteString
func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)
    WriteString writes s to w with all replacements performed.

The 'go doc' tool also has some flags including a flag to list both exported and unexported symbols (-u) and to respect case when matching symbols (-c); normally lower- case letters match either case.

Jsish

prompt$ jsish
Jsish interactive: see 'help [cmd]'
# help
Jsish interactive executes commands, uses tab for completions, and has help for the following builtin commands:

     Array Boolean CData CEnum CStruct CType Channel Debugger Event File
     Function Info Interp JSON Math Number Object RegExp Signal Socket
     Sqlite String System Util Vfs WebSocket Zvfs assert clearInterval
     console decodeURI encodeURI exec exit format isFinite isMain isNaN
     load log noOp parseFloat parseInt parseOpts printf provide puts quote
     require runModule setInterval setTimeout sleep source strftime strptime
     unload update 

Help can also take options.  For example to display in a web browser try:

    help -web true WebSocket

Module help can also be displayed (non-web), as in 'help Jsi_Websrv`.
Builtin modules include:

     Jsi_Archive Jsi_CData Jsi_Csspp Jsi_Debug Jsi_DebugUI Jsi_GenDeep
     Jsi_Help Jsi_Htmlpp Jsi_Jspp Jsi_Markdeep Jsi_Module Jsi_Safe Jsi_SqliteUI
     Jsi_UnitTest Jsi_Vfs Jsi_Websrv Jsi_Wget
# help File
File.method(...)
Commands for accessing the filesystem
Methods: atime chdir chmod copy dirname executable exists extension glob isdir isfile isrelative join link lstat mkdir mknod mtime owned pwd read readable readlink realpath remove rename rootname size stat tail tempfile truncate type writable write

[File.glob options]
Option          Type    Description [Flags]
----------------------------------------------------------------------------
dir             STRING  The start directory: this path will not be prepended to results.
maxDepth        INT     Maximum directory depth to recurse into.
maxDiscard      INT     Maximum number of items to discard before giving up.
dirFilter       FUNC    Filter function for directories, returning false to discard. @function(dir:string)
filter          FUNC    Filter function to call with each file, returning false to discard. @function(file:string)
limit           INT     The maximum number of results to return/count.
noTypes         STRKEY  Filter files to exclude these "types".
prefix          STRKEY  String prefix to add to each file in list.
recurse         BOOL    Recurse into sub-directories.
retCount        BOOL    Return only the count of matches.
tails           BOOL    Returned only tail of path.
types           STRKEY  Filter files to include type: one or more of chars 'fdlpsbc' for file, directory, link, etc.

Perl 6

Perl 6 help is generally in a specialized text format known as POD (Plain Old Documentation). It is sometimes referred to as POD6 to distinguish it from Perl 5 POD which is slightly different and not completely compatible. Perl 6 has a local command line help app: p6doc. It also has online browsable HTML documentation at docs.perl6.org. If you want to download the HTML docs for a local copy, or just prefer to browse the documentation as a single page docs.perl6.org/perl6.html may be more to your preference. If you prefer a different format, there are utilities available to convert the POD docs to several different formats; Markdown, PDF, Latex, plain text, etc.

Individual Perl 6 scripts are to some extent self-documenting. If the script has a MAIN sub, and it is called with improper parameters, it will display an automatically generated help message showing the various possible parameters, which are required, which are optional, and what type each takes:

<lang perl6>sub MAIN(

   Str $run,             #= Task or file name
   Str :$lang = 'perl6', #= Language, default perl6
   Int :$skip = 0,       #= Skip # to jump partially into a list
   Bool :f(:$force),     #= Override any skip parameter

) {

   # do whatever

}</lang>

When saved locally as main.p6 and invoked with no (or wrong) passed parameters:
Usage:
  main.p6 [--lang=<Str>] [--skip=<Int>] [-f|--force] <run>
  
    <run>           Task or file name
    --lang=<Str>    Language, default perl6
    --skip=<Int>    Skip # to jump partially into a list
    -f|--force      Override any skip parameter

REXX

Some REXXes offer interactive help   (via HELP or some other command).

Other REXXes have an HTML document or a PDF for showing command syntax and other general information on use of the language.

Each REXX has it's own documentation, and viewing it would depend on the host environment.