Skip to content

Commit 46326cc

Browse files
committed
Include manpages for lima and limactl commands
The "limactl.1" and subcommands are being dynamically generated. There is one manual page for each subcommand, e.g. limactl-start Signed-off-by: Anders F Björklund <[email protected]>
1 parent 84541d0 commit 46326cc

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ GO_BUILD := $(GO) build -ldflags="-s -w -X $(PACKAGE)/pkg/version.Version=$(VERS
3232
.NOTPARALLEL:
3333

3434
.PHONY: all
35-
all: binaries
35+
all: binaries manpages
3636

3737
exe: _output/bin/limactl$(exe)
3838

@@ -113,6 +113,11 @@ _output/share/lima/lima-guestagent.Linux-riscv64:
113113
GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
114114
chmod 644 $@
115115

116+
.PHONY: manpages
117+
manpages: _output/bin/limactl$(exe)
118+
@mkdir -p _output/share/man/man1
119+
$< generate-man _output/share/man/man1
120+
116121
.PHONY: diagrams
117122
diagrams: docs/lima-sequence-diagram.png
118123
docs/lima-sequence-diagram.png: docs/images/lima-sequence-diagram.puml
@@ -138,6 +143,8 @@ uninstall:
138143
"$(DEST)/bin/docker.lima" \
139144
"$(DEST)/bin/podman.lima" \
140145
"$(DEST)/bin/kubectl.lima" \
146+
"$(DEST)/share/man/man1/lima.1" \
147+
"$(DEST)/share/man/man1/limactl"*".1" \
141148
"$(DEST)/share/lima" "$(DEST)/share/doc/lima"
142149
if [ "$$(readlink "$(DEST)/bin/nerdctl")" = "nerdctl.lima" ]; then rm "$(DEST)/bin/nerdctl"; fi
143150
if [ "$$(readlink "$(DEST)/bin/apptainer")" = "apptainer.lima" ]; then rm "$(DEST)/bin/apptainer"; fi

cmd/limactl/genman.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/cpuguy83/go-md2man/v2/md2man"
8+
"github.com/sirupsen/logrus"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/cobra/doc"
11+
)
12+
13+
func newGenManCommand() *cobra.Command {
14+
genmanCommand := &cobra.Command{
15+
Use: "generate-man DIR",
16+
Short: "Generate manual pages",
17+
Args: WrapArgsError(cobra.MinimumNArgs(1)),
18+
RunE: genmanAction,
19+
Hidden: true,
20+
}
21+
return genmanCommand
22+
}
23+
24+
func genmanAction(cmd *cobra.Command, args []string) error {
25+
dir := args[0]
26+
logrus.Infof("Generating man %q", dir)
27+
// lima(1)
28+
filePath := filepath.Join(dir, "lima.1")
29+
md := "LIMA 1\n======" + `
30+
# NAME
31+
lima - ` + cmd.Root().Short + `
32+
# SYNOPSIS
33+
**lima** [_COMMAND_...]
34+
# DESCRIPTION
35+
lima is an alias for "limactl shell default".
36+
The instance name ("default") can be changed by specifying $LIMA_INSTANCE.
37+
38+
The shell and initial workdir inside the instance can be specified via $LIMA_SHELL
39+
and $LIMA_WORKDIR.
40+
# SEE ALSO
41+
**limactl**(1)
42+
`
43+
out := md2man.Render([]byte(md))
44+
if err := os.WriteFile(filePath, out, 0644); err != nil {
45+
return err
46+
}
47+
// limactl(1)
48+
header := &doc.GenManHeader{
49+
Title: "LIMACTL",
50+
Section: "1",
51+
}
52+
return doc.GenManTree(cmd.Root(), header, dir)
53+
}

cmd/limactl/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ func newApp() *cobra.Command {
5252
$ limactl stop
5353
5454
See also example YAMLs: %s`, examplesDir),
55-
SilenceUsage: true,
56-
SilenceErrors: true,
55+
SilenceUsage: true,
56+
SilenceErrors: true,
57+
DisableAutoGenTag: true,
5758
}
5859
rootCmd.PersistentFlags().String("log-level", "", "Set the logging level [trace, debug, info, warn, error]")
5960
rootCmd.PersistentFlags().Bool("debug", false, "debug mode")
@@ -109,6 +110,7 @@ func newApp() *cobra.Command {
109110
newEditCommand(),
110111
newFactoryResetCommand(),
111112
newDiskCommand(),
113+
newGenManCommand(),
112114
)
113115
return rootCmd
114116
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/containerd/continuity v0.3.0
1212
github.com/containers/gvisor-tap-vsock v0.6.1
1313
github.com/coreos/go-semver v0.3.1
14+
github.com/cpuguy83/go-md2man/v2 v2.0.2
1415
github.com/cyphar/filepath-securejoin v0.2.3
1516
github.com/digitalocean/go-qemu v0.0.0-20210326154740-ac9e0b687001
1617
github.com/diskfs/go-diskfs v1.3.0
@@ -92,6 +93,7 @@ require (
9293
github.com/pkg/errors v0.9.1 // indirect
9394
github.com/pkg/sftp v1.13.5 // indirect
9495
github.com/rivo/uniseg v0.2.0 // indirect
96+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
9597
github.com/spf13/pflag v1.0.5 // indirect
9698
github.com/u-root/uio v0.0.0-20210528114334-82958018845c // indirect
9799
go.uber.org/atomic v1.7.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+
118118
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
119119
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
120120
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
121+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
121122
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
122123
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
123124
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
@@ -464,6 +465,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
464465
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
465466
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
466467
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
468+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
467469
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
468470
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
469471
github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI=

0 commit comments

Comments
 (0)