From 7d2ee16e2dc7b6b347789526df4f27ca7fd34a55 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Wed, 14 Sep 2016 00:40:14 +0300 Subject: [PATCH] generate documentation and embed in binary --- doc.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ docstring.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ gen/docstring.sh | 9 ++++++++ main.go | 6 ++++++ 4 files changed, 125 insertions(+) create mode 100644 doc.go create mode 100644 docstring.go create mode 100755 gen/docstring.sh diff --git a/doc.go b/doc.go new file mode 100644 index 00000000..2b1987a2 --- /dev/null +++ b/doc.go @@ -0,0 +1,55 @@ +//go:generate gen/docstring.sh + +/* +lf is a terminal file manager. + +Keys + +Following commands along with the default keybindings are provided by lf. + + up (default "k" and "") + half-up (default "") + page-up (default "") + down (default "j" and "") + half-down (default "") + page-down (default "") + updir (default "h" and "") + open (default "l" and "") + quit (default "q") + bot (default "G") + top (default "gg") + read (default ":") + read-shell (default "$") + read-shell-wait (default "!") + read-shell-async (default "&") + search (default "/") + search-back (default "?") + toggle (default "") + yank (default "y") + delete (default "d") + paste (default "p") + renew (default "") + +Options + +Following options can be used to customize the behavior of lf. + + hidden bool (default off) + preview bool (default on) + scrolloff int (default 0) + tabstop int (default 8) + ifs string (default not set) + shell string (default $SHELL) + showinfo string (default none) + sortby string (default name) + ratios string (default 1:2:3) + +Variables + +Following variables are exported for shell commands. + + $f current file + $fs marked file(s) (separated with ':') + $fx current file or marked file(s) if any +*/ +package main diff --git a/docstring.go b/docstring.go new file mode 100644 index 00000000..0a9ea1ad --- /dev/null +++ b/docstring.go @@ -0,0 +1,55 @@ +package main + +var genDocString = `lf is a terminal file manager. + + +Keys + +Following commands along with the default keybindings are provided by lf. + + up (default "k" and "") + half-up (default "") + page-up (default "") + down (default "j" and "") + half-down (default "") + page-down (default "") + updir (default "h" and "") + open (default "l" and "") + quit (default "q") + bot (default "G") + top (default "gg") + read (default ":") + read-shell (default "$") + read-shell-wait (default "!") + read-shell-async (default "&") + search (default "/") + search-back (default "?") + toggle (default "") + yank (default "y") + delete (default "d") + paste (default "p") + renew (default "") + + +Options + +Following options can be used to customize the behavior of lf. + + hidden bool (default off) + preview bool (default on) + scrolloff int (default 0) + tabstop int (default 8) + ifs string (default not set) + shell string (default $SHELL) + showinfo string (default none) + sortby string (default name) + ratios string (default 1:2:3) + + +Variables + +Following variables are exported for shell commands. + + $f current file + $fs marked file(s) (separated with ':') + $fx current file or marked file(s) if any` diff --git a/gen/docstring.sh b/gen/docstring.sh new file mode 100755 index 00000000..23bc9329 --- /dev/null +++ b/gen/docstring.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Generates `docstring.go` having `genDocString` variable with `go doc` output. +# +# This script is called in `doc.go` using `go generate` to embed the +# documentation inside the binary in order to show it on request with `-doc` +# command line flag. Thus the same documentation is used for online and +# terminal display. + +echo "package main\n\nvar genDocString = \`$(go doc)\`" > docstring.go diff --git a/main.go b/main.go index f007d4f4..af60071d 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,7 @@ func startServer() { } func main() { + showDoc := flag.Bool("doc", false, "show documentation") serverMode := flag.Bool("server", false, "start server (automatic)") cpuprofile := flag.String("cpuprofile", "", "path to the file to write the cpu profile") flag.StringVar(&gLastDirPath, "last-dir-path", "", "path to the file to write the last dir on exit (to use for cd)") @@ -73,6 +74,11 @@ func main() { flag.Parse() + if *showDoc { + fmt.Println(genDocString) + return + } + if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil {