Skip to content

Commit 8cff937

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 f70a609 commit 8cff937

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")
@@ -110,6 +111,7 @@ func newApp() *cobra.Command {
110111
newFactoryResetCommand(),
111112
newDiskCommand(),
112113
newUsernetCommand(),
114+
newGenManCommand(),
113115
)
114116
return rootCmd
115117
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/containerd/continuity v0.3.0
1313
github.com/containers/gvisor-tap-vsock v0.6.1
1414
github.com/coreos/go-semver v0.3.1
15+
github.com/cpuguy83/go-md2man/v2 v2.0.2
1516
github.com/cyphar/filepath-securejoin v0.2.3
1617
github.com/digitalocean/go-qemu v0.0.0-20210326154740-ac9e0b687001
1718
github.com/diskfs/go-diskfs v1.3.0
@@ -96,6 +97,7 @@ require (
9697
github.com/pkg/errors v0.9.1 // indirect
9798
github.com/pkg/sftp v1.13.5 // indirect
9899
github.com/rivo/uniseg v0.2.0 // indirect
100+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
99101
github.com/spf13/pflag v1.0.5 // indirect
100102
github.com/u-root/uio v0.0.0-20210528114334-82958018845c // indirect
101103
go.uber.org/atomic v1.7.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+
122122
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
123123
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
124124
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
125+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
125126
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
126127
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
127128
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
@@ -474,6 +475,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
474475
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
475476
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
476477
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
478+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
477479
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
478480
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
479481
github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI=

0 commit comments

Comments
 (0)