mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 04:21:01 +01:00
added manpage and manpage display commands
This commit is contained in:
28
main.go
28
main.go
@@ -18,8 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/chzyer/readline"
|
||||
@@ -36,6 +39,7 @@ Usage: rpn [-bdvh] [<operator>]
|
||||
Options:
|
||||
-b, --batchmode enable batch mode
|
||||
-d, --debug enable debug mode
|
||||
-m, --manual show manual
|
||||
-v, --version show version
|
||||
-h, --help show help
|
||||
|
||||
@@ -49,6 +53,7 @@ func main() {
|
||||
|
||||
showversion := false
|
||||
showhelp := false
|
||||
showmanual := false
|
||||
enabledebug := false
|
||||
configfile := ""
|
||||
|
||||
@@ -56,6 +61,7 @@ func main() {
|
||||
flag.BoolVarP(&enabledebug, "debug", "d", false, "debug mode")
|
||||
flag.BoolVarP(&showversion, "version", "v", false, "show version")
|
||||
flag.BoolVarP(&showhelp, "help", "h", false, "show usage")
|
||||
flag.BoolVarP(&showmanual, "manual", "m", false, "show manual")
|
||||
flag.StringVarP(&configfile, "config", "c",
|
||||
os.Getenv("HOME")+"/.rpn.lua", "config file (lua format)")
|
||||
|
||||
@@ -75,6 +81,11 @@ func main() {
|
||||
calc.ToggleDebug()
|
||||
}
|
||||
|
||||
if showmanual {
|
||||
man()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// the lua state object is global, instanciate it early
|
||||
L = lua.NewState(lua.Options{SkipOpenLibs: true})
|
||||
defer L.Close()
|
||||
@@ -141,3 +152,20 @@ func inputIsStdin() bool {
|
||||
stat, _ := os.Stdin.Stat()
|
||||
return (stat.Mode() & os.ModeCharDevice) == 0
|
||||
}
|
||||
|
||||
func man() {
|
||||
man := exec.Command("less", "-")
|
||||
|
||||
var b bytes.Buffer
|
||||
b.Write([]byte(manpage))
|
||||
|
||||
man.Stdout = os.Stdout
|
||||
man.Stdin = &b
|
||||
man.Stderr = os.Stderr
|
||||
|
||||
err := man.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user