diff options
Diffstat (limited to 'man/manview')
| -rw-r--r-- | man/manview/data.go | 43 | ||||
| -rw-r--r-- | man/manview/help.txt | 37 | ||||
| -rw-r--r-- | man/manview/manview.go | 36 | ||||
| -rw-r--r-- | man/manview/templates/pik.1.man.tmpl | 31 | ||||
| -rw-r--r-- | man/manview/version.txt | 1 |
5 files changed, 148 insertions, 0 deletions
diff --git a/man/manview/data.go b/man/manview/data.go new file mode 100644 index 0000000..7e42fcc --- /dev/null +++ b/man/manview/data.go @@ -0,0 +1,43 @@ +package manview + +import ( + _ "embed" + _ "github.com/ewy1/pik/flags" + "github.com/ewy1/pik/spool" + "github.com/spf13/pflag" + "runtime" + "runtime/debug" + "time" +) + +//go:embed version.txt +var version string + +type ManData struct { + Flags []pflag.Flag + Now string + Revision string + Runtime string + Version string + ExitCodes map[int]*spool.ExitCode +} + +func NewData() ManData { + var flags []pflag.Flag + pflag.Parse() + pflag.VisitAll(func(flag *pflag.Flag) { + flags = append(flags, *flag) + }) + info, ok := debug.ReadBuildInfo() + if !ok { + _, _ = spool.Panic(spool.NoDebugInfo, "could not read debug info\n") + } + return ManData{ + Flags: flags, + Now: time.Now().Format(time.DateTime), + Runtime: runtime.Version(), + Version: version, + Revision: info.Main.Version, + ExitCodes: spool.CodeMap, + } +} diff --git a/man/manview/help.txt b/man/manview/help.txt new file mode 100644 index 0000000..8c7e943 --- /dev/null +++ b/man/manview/help.txt @@ -0,0 +1,37 @@ +Usage: pik [OPTION]... [SOURCE] [TARGET] [ARG]... + +This help content is being replaced with manual pages. To view them, try `man pik`. + +If no arguments are provided, the TUI will open. + +Otherwise, pik will attempt to run the $TARGET script in $SOURCE. + +OPTIONS: + --help + print this information + -a, --all + in addition to crawling, also load all cached sources + -h, --here + run in the current working directory instead of the source folder + -@, --at [LOCATION] + run at $LOCATION instead of the source folder + -s, --single + skip triggers (pre, post, final targets) + -d, --dry + instead of running targets, echo their command + -r, --root + prefix target command with sudo + -y, --yes + assume yes for yes/no prompts + --env [ENVTYPE] [--env [OTHER]]... + load environment files that look like they belong to this category + -v, --version + print pik version and exit + -l, --list + list all available sources and targets instead of doing anything interactive + -i, -inline + disable TUI alt screen + --edit + open the target in $EDITOR instead of running it + --install-completion + install completion in your shell rc file (bash or zsh currently supported) diff --git a/man/manview/manview.go b/man/manview/manview.go new file mode 100644 index 0000000..777f2cd --- /dev/null +++ b/man/manview/manview.go @@ -0,0 +1,36 @@ +package manview + +import ( + "embed" + _ "embed" + "github.com/ewy1/pik/spool" + "os" + "os/exec" + "strings" + "text/template" +) + +//go:embed templates +var pageTemplates embed.FS + +var page = template.Must(template.ParseFS(pageTemplates, "templates/*")) + +func View(fallback string) error { + man, manErr := exec.LookPath("man") + if manErr != nil { + _, err := spool.Print("%v\n", fallback) + return err + } else { + t := &strings.Builder{} + err := page.Execute(t, NewData()) + if err != nil { + return err + } + reader := strings.NewReader(t.String()) + cmd := exec.Command(man, "-l", "-") + cmd.Stdin = reader + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() + } +} diff --git a/man/manview/templates/pik.1.man.tmpl b/man/manview/templates/pik.1.man.tmpl new file mode 100644 index 0000000..53f1cfd --- /dev/null +++ b/man/manview/templates/pik.1.man.tmpl @@ -0,0 +1,31 @@ +{{- /*gotype: github.com/ewy1/pik/man.ManData*/ -}} +.TH PIK 1 {{.Version}} {{.Runtime}} +.sh NAME +pik \- file based task runner +.SH SYNOPSIS +.B pik +[\fIOPTION\fR]... [[\fISOURCE\fR] [\fITARGET\fR]] [\fIARG\fR]... +.SH DESCRIPTION +.B pik +executes scripts from the .pik folder or external runners. +.SH EXAMPLES +Given a .pik folder in your current working directory containing "script.sh", calling +.B pik script +will start that script. +.PP To start a script from another location, pass that as the SOURCE before the TARGET. +Example: +.B pik project build +will start ../../.pik/build.py if it exists. +.SH OPTIONS +{{ range .Flags -}} +.TP +.BR \-\-{{.Name }} {{ if .Shorthand }}, \-{{ .Shorthand }}{{ end }} = {{ .Value.Type }} {{ if .DefValue }} ({{.DefValue}}) {{- end }} +{{ .Usage }} +{{ end }} +.SH EXIT CODES +If the target runs and returns a non-zero error code, we pass that forward instead. +{{ range .ExitCodes -}} +.TP +.BR {{ .Value }} +{{ .Message }} +{{ end }}
\ No newline at end of file diff --git a/man/manview/version.txt b/man/manview/version.txt new file mode 100644 index 0000000..3b2e7a0 --- /dev/null +++ b/man/manview/version.txt @@ -0,0 +1 @@ +0.0.0-dev
\ No newline at end of file |
