Skip to content

Commit cd892f6

Browse files
committed
add documentation to repo
Signed-off-by: olalekan odukoya <[email protected]>
1 parent cfddc0d commit cd892f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4923
-19
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ integration: build
8080
.PHONY: images-sha
8181
images-sha:
8282
bash embedded/images/images_sha.sh
83+
84+
.PHONY: generate-cli-docs
85+
generate-cli-docs:
86+
_output/binaries/colima-Darwin-arm64 generate-doc --type docsy website/_output/docsy

cmd/completion.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,40 @@ func completionCmd() *cobra.Command {
1515
Long: `To load completions:
1616
Bash:
1717
18-
$ source <(colima completion bash)
18+
$ source <(colima completion bash)
1919
20-
# To load completions for each session, execute once:
21-
# Linux:
22-
$ colima completion bash > /etc/bash_completion.d/colima
23-
# macOS:
24-
$ colima completion bash > /usr/local/etc/bash_completion.d/colima
20+
To load completions for each session, execute once:
21+
Linux:
22+
$ colima completion bash > /etc/bash_completion.d/colima
23+
macOS:
24+
$ colima completion bash > /usr/local/etc/bash_completion.d/colima
2525
2626
Zsh:
2727
28-
# If shell completion is not already enabled in your environment,
29-
# you will need to enable it. You can execute the following once:
28+
If shell completion is not already enabled in your environment,
29+
you will need to enable it. You can execute the following once:
3030
31-
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
31+
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
3232
33-
# To load completions for each session, execute once:
34-
$ colima completion zsh > "${fpath[1]}/_colima"
33+
To load completions for each session, execute once:
34+
$ colima completion zsh > "${fpath[1]}/_colima"
3535
36-
# You will need to start a new shell for this setup to take effect.
36+
You will need to start a new shell for this setup to take effect.
3737
3838
fish:
3939
40-
$ colima completion fish | source
40+
$ colima completion fish | source
4141
42-
# To load completions for each session, execute once:
43-
$ colima completion fish > ~/.config/fish/completions/colima.fish
42+
To load completions for each session, execute once:
43+
$ colima completion fish > ~/.config/fish/completions/colima.fish
4444
4545
PowerShell:
4646
47-
PS> colima completion powershell | Out-String | Invoke-Expression
47+
PS> colima completion powershell | Out-String | Invoke-Expression
4848
49-
# To load completions for every new session, run:
50-
PS> colima completion powershell > colima.ps1
51-
# and source this file from your PowerShell profile.
49+
To load completions for every new session, run:
50+
PS> colima completion powershell > colima.ps1
51+
and source this file from your PowerShell profile.
5252
`,
5353
DisableFlagsInUseLine: true,
5454
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},

cmd/generate-doc.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"io/fs"
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
11+
"github.com/abiosoft/colima/cmd/root"
12+
"github.com/sirupsen/logrus"
13+
"github.com/spf13/cobra"
14+
"github.com/spf13/cobra/doc"
15+
)
16+
17+
func newGenDocCommand() *cobra.Command {
18+
genmanCommand := &cobra.Command{
19+
Use: "generate-doc DIR",
20+
Short: "Generate cli-reference pages",
21+
Args: cobra.ExactArgs(1),
22+
RunE: gendocAction,
23+
Hidden: true,
24+
}
25+
genmanCommand.Flags().String("type", "docsy", "Output type (docsy)")
26+
return genmanCommand
27+
}
28+
29+
func gendocAction(cmd *cobra.Command, args []string) error {
30+
outputType, err := cmd.Flags().GetString("type")
31+
if err != nil {
32+
return err
33+
}
34+
homeDir, err := os.UserHomeDir()
35+
if err != nil {
36+
return err
37+
}
38+
39+
dir := args[0]
40+
41+
if err := os.MkdirAll(dir, 0755); err != nil {
42+
return fmt.Errorf("failed to create directory %s: %w", dir, err)
43+
}
44+
45+
switch outputType {
46+
case "docsy":
47+
if err := genDocsy(cmd, dir); err != nil {
48+
return err
49+
}
50+
}
51+
return replaceAll(dir, homeDir, "~")
52+
}
53+
54+
func genDocsy(cmd *cobra.Command, dir string) error {
55+
return doc.GenMarkdownTreeCustom(cmd.Root(), dir, func(s string) string {
56+
name := filepath.Base(s)
57+
name = strings.ReplaceAll(name, "colima", "")
58+
name = strings.ReplaceAll(name, "_", " ")
59+
name = strings.TrimSuffix(name, filepath.Ext(name))
60+
return fmt.Sprintf(`---
61+
title: %s
62+
weight: 3
63+
---
64+
`, name)
65+
}, func(s string) string {
66+
return strings.TrimSuffix(s, filepath.Ext(s))
67+
})
68+
}
69+
70+
func replaceAll(dir, text, replacement string) error {
71+
logrus.Infof("Replacing %q with %q", text, replacement)
72+
return filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
73+
if err != nil {
74+
return err
75+
}
76+
if path == dir {
77+
return nil
78+
}
79+
if info.IsDir() {
80+
return filepath.SkipDir
81+
}
82+
in, err := os.ReadFile(path)
83+
if err != nil {
84+
return fmt.Errorf("failed to read file %s: %w", path, err)
85+
}
86+
out := bytes.ReplaceAll(in, []byte(text), []byte(replacement))
87+
err = os.WriteFile(path, out, 0o644)
88+
if err != nil {
89+
return fmt.Errorf("failed to write file %s: %w", path, err)
90+
}
91+
return nil
92+
})
93+
}
94+
95+
func init() {
96+
root.Cmd().AddCommand(newGenDocCommand())
97+
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ require (
1616
)
1717

1818
require (
19+
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
1920
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2021
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
2122
github.com/mattn/go-colorable v0.1.13 // indirect
2223
github.com/mattn/go-isatty v0.0.20 // indirect
24+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
2325
github.com/spf13/pflag v1.0.6 // indirect
2426
github.com/stretchr/testify v1.8.4 // indirect
2527
golang.org/x/sys v0.34.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
22
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
34
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
45
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
56
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -23,6 +24,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
2324
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2425
github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY=
2526
github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc=
27+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
2628
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
2729
github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs=
2830
github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=

website/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/public
2+
resources/
3+
node_modules/
4+
.hugo_build.lock

website/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/*

website/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-FileCopyrightText: Copyright The Colima Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
# See also: package.json
4+
NPM ?= npm
5+
6+
build serve: _output/docsy node_modules/.bin/hugo
7+
$(NPM) run $@
8+
9+
_output/docsy:
10+
$(MAKE) -C .. docsy
11+
12+
node_modules/.bin/hugo:
13+
$(NPM) install
14+
15+
clean:
16+
$(NPM) run $@
17+
rm -Rf _output

website/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The source of the Colima website (https://colima.io)
2+
3+
This directory is the [Netlify base directory](https://docs.netlify.com/configure-builds/overview/) of [https://colima.io](https://colima.io/) .

0 commit comments

Comments
 (0)