diff options
Diffstat (limited to 'man')
| -rw-r--r-- | man/data.go | 43 | ||||
| -rw-r--r-- | man/help.txt | 37 | ||||
| -rw-r--r-- | man/man.go | 50 | ||||
| -rw-r--r-- | man/man_test.go | 18 | ||||
| -rw-r--r-- | man/templates/pik.1.man.tmpl | 31 | ||||
| -rw-r--r-- | man/version.txt | 1 |
6 files changed, 180 insertions, 0 deletions
diff --git a/man/data.go b/man/data.go new file mode 100644 index 0000000..322da8f --- /dev/null +++ b/man/data.go @@ -0,0 +1,43 @@ +package main + +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/help.txt b/man/help.txt new file mode 100644 index 0000000..8c7e943 --- /dev/null +++ b/man/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/man.go b/man/man.go new file mode 100644 index 0000000..49018ed --- /dev/null +++ b/man/man.go @@ -0,0 +1,50 @@ +package main + +import ( + "embed" + "github.com/ewy1/pik/spool" + "github.com/spf13/pflag" + "os" + "path/filepath" + "strings" + "text/template" +) + +//go:embed templates +var templates embed.FS + +var ManOutput = pflag.String(manFlagName, "out", "directory to write man pages to (gets created)") + +const manFlagName = "man-output" +const templateDir = "templates" +const manExtension = ".man" +const templateExtension = ".tmpl" + +func main() { + pflag.Parse() + tmpl, err := template.ParseFS(templates, filepath.Join(templateDir, "*")) + if err != nil { + _, _ = spool.Panic(spool.ManFailure, "%v\n", err) + return + } + err = os.MkdirAll(*ManOutput, os.ModePerm) + if err != nil { + _, _ = spool.Panic(spool.ManFailure, "%v\n", err) + } + d := NewData() + for _, t := range tmpl.Templates() { + if !strings.HasSuffix(t.Name(), manExtension+templateExtension) { + continue + } + + resultFile, err := os.OpenFile(filepath.Join(*ManOutput, strings.TrimSuffix(strings.TrimSuffix(t.Name(), templateExtension), manExtension)), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600) + if err != nil { + _, _ = spool.Panic(spool.ManFailure, "%v\n", err) + } + + err = t.Execute(resultFile, d) + if err != nil { + _, _ = spool.Panic(spool.ManFailure, "%v\n", err) + } + } +} diff --git a/man/man_test.go b/man/man_test.go new file mode 100644 index 0000000..4b48c0f --- /dev/null +++ b/man/man_test.go @@ -0,0 +1,18 @@ +//go:build test + +package main + +import ( + "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" + "path/filepath" + "testing" +) + +func TestMan(t *testing.T) { + d := t.TempDir() + err := pflag.Set(manFlagName, d) + assert.NoError(t, err) + assert.NotPanics(t, main) + assert.FileExists(t, filepath.Join(d, "pik.1.man")) +} diff --git a/man/templates/pik.1.man.tmpl b/man/templates/pik.1.man.tmpl new file mode 100644 index 0000000..53f1cfd --- /dev/null +++ b/man/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/version.txt b/man/version.txt new file mode 100644 index 0000000..3b2e7a0 --- /dev/null +++ b/man/version.txt @@ -0,0 +1 @@ +0.0.0-dev
\ No newline at end of file |
