Skip to content

Commit e57ac78

Browse files
authored
Merge pull request #1521 from afbjorklund/manpages
Include manpages for lima and limactl commands
2 parents a4fdc5d + aa91d2b commit e57ac78

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
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: 5 additions & 3 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")
@@ -82,7 +83,7 @@ func newApp() *cobra.Command {
8283
formatter.ForceColors = true
8384
logrus.StandardLogger().SetFormatter(formatter)
8485
}
85-
if os.Geteuid() == 0 {
86+
if os.Geteuid() == 0 && cmd.Name() != "generate-man" {
8687
return errors.New("must not run as the root")
8788
}
8889
// Make sure either $HOME or $LIMA_HOME is defined, so we don't need
@@ -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
@@ -120,6 +120,7 @@ github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+
120120
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
121121
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
122122
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
123+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
123124
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
124125
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
125126
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
@@ -473,6 +474,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
473474
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
474475
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
475476
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
477+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
476478
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
477479
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
478480
github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI=

0 commit comments

Comments
 (0)