Skip to content

Commit 9538969

Browse files
committed
improve doc for CLI
improve UI for code example in webui
1 parent a2d962b commit 9538969

12 files changed

Lines changed: 497 additions & 155 deletions

File tree

pkg/cli/docs.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func writeCommand(c *Command, f *os.File) error {
4242
}
4343

4444
if c.Use != "" {
45-
use := fmt.Sprintf("```bash\n%s\n```", c.Use)
45+
use := fmt.Sprintf("```bash tab=Bash\n%s\n```\n\n", c.Use)
4646
if _, err := f.WriteString(fmt.Sprintf("## Usage\n\n%s\n\n", use)); err != nil {
4747
return err
4848
}
@@ -120,10 +120,6 @@ func writeFlag(w io.StringWriter, f *Flag, envPrefix string) error {
120120
}
121121

122122
if len(f.Examples) > 0 {
123-
if _, err := w.WriteString("### Examples\n\n"); err != nil {
124-
return err
125-
}
126-
127123
for _, example := range f.Examples {
128124
if example.Title != "" {
129125
if _, err := w.WriteString(fmt.Sprintf("### %s\n\n", example.Title)); err != nil {
@@ -139,8 +135,8 @@ func writeFlag(w io.StringWriter, f *Flag, envPrefix string) error {
139135

140136
for _, code := range example.Codes {
141137
codeType := "bash"
142-
if code.Type != "" {
143-
codeType = code.Type
138+
if code.Language != "" {
139+
codeType = code.Language
144140
}
145141
var s string
146142
if code.Title != "" {

pkg/cli/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ type Example struct {
205205
}
206206

207207
type Code struct {
208-
Title string
209-
Source string
210-
Type string
208+
Title string
209+
Source string
210+
Language string
211211
}
212212

213213
type FlagBuilder struct {

pkg/cmd/mokapi/flags/providers_file.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ When set, Mokapi loads dynamic configuration files from the specified path. You
2020
Examples: []cli.Example{
2121
{
2222
Codes: []cli.Code{
23-
{Title: "Cli", Source: "--providers-file directory=/foo,fileSkipPrefix=skip"},
23+
{Title: "CLI", Source: "--providers-file directory=/foo,fileSkipPrefix=skip"},
2424
{Title: "Env", Source: "MOKAPI_FILE=directory=/foo,fileSkipPrefix=skip"},
25-
{Title: "File", Source: "providers:\n file:\n directory: /foo\n fileSkipPrefix: [skip]", Type: "yaml"},
25+
{Title: "File", Source: "providers:\n file:\n directory: /foo\n fileSkipPrefix: [skip]", Language: "yaml"},
2626
},
2727
},
2828
},
@@ -35,9 +35,9 @@ This option can be used multiple times to load additional files.`,
3535
Examples: []cli.Example{
3636
{
3737
Codes: []cli.Code{
38-
{Title: "Cli", Source: "--providers-file-filename foobar.yaml"},
38+
{Title: "CLI", Source: "--providers-file-filename foobar.yaml"},
3939
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_FILENAME=foobar.yaml"},
40-
{Title: "File", Source: "providers:\n file:\n filenames: [foobar.yaml]", Type: "yaml"},
40+
{Title: "File", Source: "providers:\n file:\n filenames: [foobar.yaml]", Language: "yaml"},
4141
},
4242
},
4343
},
@@ -50,9 +50,9 @@ This option is equivalent to using providers-file-filename multiple times, but a
5050
Examples: []cli.Example{
5151
{
5252
Codes: []cli.Code{
53-
{Title: "Cli", Source: "--providers-file-filenames foo.yaml bar.yaml"},
53+
{Title: "CLI", Source: "--providers-file-filenames foo.yaml bar.yaml"},
5454
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_FILENAMES=foo.yaml bar.yaml"},
55-
{Title: "File", Source: "providers:\n file:\n filenames: [foo.yaml, bar.yaml]", Type: "yaml"},
55+
{Title: "File", Source: "providers:\n file:\n filenames: [foo.yaml, bar.yaml]", Language: "yaml"},
5656
},
5757
},
5858
},
@@ -65,9 +65,9 @@ All supported configuration files in the directory are processed. The directory
6565
Examples: []cli.Example{
6666
{
6767
Codes: []cli.Code{
68-
{Title: "Cli", Source: "--providers-file-directory ./configs"},
68+
{Title: "CLI", Source: "--providers-file-directory ./configs"},
6969
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_DIRECTORY=./configs"},
70-
{Title: "File", Source: "providers:\n file:\n directories: [./configs]", Type: "yaml"},
70+
{Title: "File", Source: "providers:\n file:\n directories: [./configs]", Language: "yaml"},
7171
},
7272
},
7373
},
@@ -80,9 +80,9 @@ All supported configuration files in each directory are processed. Directories a
8080
Examples: []cli.Example{
8181
{
8282
Codes: []cli.Code{
83-
{Title: "Cli", Source: "--providers-file-directories ./configs ./data"},
83+
{Title: "CLI", Source: "--providers-file-directories ./configs ./data"},
8484
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_DIRECTORIES=./configs ./data"},
85-
{Title: "File", Source: "providers:\n file:\n directories: [./configs, ./data]", Type: "yaml"},
85+
{Title: "File", Source: "providers:\n file:\n directories: [./configs, ./data]", Language: "yaml"},
8686
},
8787
},
8888
},
@@ -96,9 +96,9 @@ By default, files and directories starting with "_" are skipped.`,
9696
Examples: []cli.Example{
9797
{
9898
Codes: []cli.Code{
99-
{Title: "Cli", Source: "--providers-file-skip-prefix skip_"},
99+
{Title: "CLI", Source: "--providers-file-skip-prefix skip_"},
100100
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_SKIP_PREFIX=skip_"},
101-
{Title: "File", Source: "providers:\n file:\n skipPrefix: [skip_]", Type: "yaml"},
101+
{Title: "File", Source: "providers:\n file:\n skipPrefix: [skip_]", Language: "yaml"},
102102
},
103103
},
104104
},
@@ -112,9 +112,9 @@ Patterns typically follow glob-style matching.`,
112112
Examples: []cli.Example{
113113
{
114114
Codes: []cli.Code{
115-
{Title: "Cli", Source: "--providers-file-include *.json *.yaml"},
115+
{Title: "CLI", Source: "--providers-file-include *.json *.yaml"},
116116
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_INCLUDE=*.json *.yaml"},
117-
{Title: "File", Source: "providers:\n file:\n include: [*.json, *.yaml]", Type: "yaml"},
117+
{Title: "File", Source: "providers:\n file:\n include: [*.json, *.yaml]", Language: "yaml"},
118118
},
119119
},
120120
},
@@ -127,8 +127,8 @@ This option is mainly intended for advanced use cases or programmatic configurat
127127
Examples: []cli.Example{
128128
{
129129
Codes: []cli.Code{
130-
{Title: "Cli", Source: "--providers-file-include[1] *.yaml"},
131-
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_INCLUDE[1]=*.yaml", Type: "yaml"},
130+
{Title: "CLI", Source: "--providers-file-include[1] *.yaml"},
131+
{Title: "Env", Source: "MOKAPI_PROVIDERS_FILE_INCLUDE[1]=*.yaml"},
132132
},
133133
},
134134
},

pkg/cmd/mokapi/flags/providers_git.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Additional flags allow you to control polling behavior, repository selection, au
2929
Examples: []cli.Example{
3030
{
3131
Codes: []cli.Code{
32-
{Title: "Cli", Source: "--providers-git pullInterval=10s,tempDir=/tempdir"},
33-
{Title: "Env", Source: "MOKAPI_GIT=pullInterval=10s,tempDir=/tempdir"},
34-
{Title: "File", Source: "providers:\n git:\n pullInterval: 10s\n tempDir: /tempdir", Type: "yaml"},
32+
{Title: "CLI", Source: "--providers-git pullInterval=10s,tempDir=/tempdir"},
33+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT=pullInterval=10s,tempDir=/tempdir"},
34+
{Title: "File", Source: "providers:\n git:\n pullInterval: 10s\n tempDir: /tempdir", Language: "yaml"},
3535
},
3636
},
3737
},
@@ -44,9 +44,9 @@ This option can be used multiple times to define additional repositories. Each r
4444
Examples: []cli.Example{
4545
{
4646
Codes: []cli.Code{
47-
{Title: "Cli", Source: "--providers-git-url https://github.com/foo/foo.git"},
48-
{Title: "Env", Source: "MOKAPI_GIT_URL=https://github.com/foo/foo.git"},
49-
{Title: "File", Source: "providers:\n git:\n urls: https://github.com/foo/foo.git", Type: "yaml"},
47+
{Title: "CLI", Source: "--providers-git-url https://github.com/foo/foo.git"},
48+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_URL=https://github.com/foo/foo.git"},
49+
{Title: "File", Source: "providers:\n git:\n urls: https://github.com/foo/foo.git", Language: "yaml"},
5050
},
5151
},
5252
},
@@ -59,9 +59,9 @@ This option is equivalent to using providers-git-url multiple times, but allows
5959
Examples: []cli.Example{
6060
{
6161
Codes: []cli.Code{
62-
{Title: "Cli", Source: "--providers-git-urls https://github.com/foo/foo.git https://github.com/bar/bar.git"},
63-
{Title: "Env", Source: "MOKAPI_GIT_URLS=https://github.com/foo/foo.git https://github.com/bar/bar.git"},
64-
{Title: "File", Source: "providers:\n git:\n urls: [https://github.com/foo/foo.git https://github.com/bar/bar.git]", Type: "yaml"},
62+
{Title: "CLI", Source: "--providers-git-urls https://github.com/foo/foo.git https://github.com/bar/bar.git"},
63+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_URLS=https://github.com/foo/foo.git https://github.com/bar/bar.git"},
64+
{Title: "File", Source: "providers:\n git:\n urls: [https://github.com/foo/foo.git https://github.com/bar/bar.git]", Language: "yaml"},
6565
},
6666
},
6767
},
@@ -74,8 +74,8 @@ The value must be a valid duration string, such as "30s", "1m", or "5m". Shorter
7474
Examples: []cli.Example{
7575
{
7676
Codes: []cli.Code{
77-
{Title: "Cli", Source: "--providers-git-pull-interval 10s"},
78-
{Title: "Env", Source: "MOKAPI_GIT_PULL_INTERVAL=10s"},
77+
{Title: "CLI", Source: "--providers-git-pull-interval 10s"},
78+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_PULL_INTERVAL=10s"},
7979
{Title: "File", Source: "providers:\n git:\n pullInterval: 10s"},
8080
},
8181
},
@@ -89,9 +89,9 @@ If not set, Mokapi uses a default temporary directory. Setting this option can b
8989
Examples: []cli.Example{
9090
{
9191
Codes: []cli.Code{
92-
{Title: "Cli", Source: "--providers-git-temp-dir /tempdir"},
93-
{Title: "Env", Source: "MOKAPI_GIT_TEMP_DIR=/tempdir"},
94-
{Title: "File", Source: "providers:\n git:\n tempDir: /tempdir", Type: "yaml"},
92+
{Title: "CLI", Source: "--providers-git-temp-dir /tempdir"},
93+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_TEMP_DIR=/tempdir"},
94+
{Title: "File", Source: "providers:\n git:\n tempDir: /tempdir", Language: "yaml"},
9595
},
9696
},
9797
},
@@ -104,9 +104,9 @@ This option allows defining repository-specific settings such as allowed files,
104104
Examples: []cli.Example{
105105
{
106106
Codes: []cli.Code{
107-
{Title: "Cli", Source: "--providers-git-repository url=https://github.com/foo/foo.git,include=*.json"},
108-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORY=url=https://github.com/foo/foo.git,tempDir=/tempdir"},
109-
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git\n include: *.json", Type: "yaml"},
107+
{Title: "CLI", Source: "--providers-git-repository url=https://github.com/foo/foo.git,include=*.json"},
108+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORY=url=https://github.com/foo/foo.git,tempDir=/tempdir"},
109+
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git\n include: *.json", Language: "yaml"},
110110
},
111111
},
112112
},
@@ -119,9 +119,9 @@ This option is equivalent to using providers-git-repository multiple times, but
119119
Examples: []cli.Example{
120120
{
121121
Codes: []cli.Code{
122-
{Title: "Cli", Source: "--providers-git-repositories url=https://github.com/foo/foo.git,include=*.json url=https://github.com/bar/bar.git,include=*.yaml"},
123-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES=url=https://github.com/foo/foo.git,include=*.json url=https://github.com/bar/bar.git,include=*.yaml"},
124-
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git\n include: [*.json]\n - url: https://github.com/bar/bar.git\n include: [*.yaml]", Type: "yaml"},
122+
{Title: "CLI", Source: "--providers-git-repositories url=https://github.com/foo/foo.git,include=*.json url=https://github.com/bar/bar.git,include=*.yaml"},
123+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES=url=https://github.com/foo/foo.git,include=*.json url=https://github.com/bar/bar.git,include=*.yaml"},
124+
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git\n include: [*.json]\n - url: https://github.com/bar/bar.git\n include: [*.yaml]", Language: "yaml"},
125125
},
126126
},
127127
},
@@ -134,9 +134,9 @@ This option is mainly intended for advanced or programmatic configurations where
134134
Examples: []cli.Example{
135135
{
136136
Codes: []cli.Code{
137-
{Title: "Cli", Source: "--providers-git-repositories[0] url=https://github.com/foo/foo.git,include=*.json"},
138-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES[0]=url=https://github.com/foo/foo.git,include=*.json"},
139-
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git\n include: [*.json]", Type: "yaml"},
137+
{Title: "CLI", Source: "--providers-git-repositories[0] url=https://github.com/foo/foo.git,include=*.json"},
138+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES[0]=url=https://github.com/foo/foo.git,include=*.json"},
139+
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git\n include: [*.json]", Language: "yaml"},
140140
},
141141
},
142142
},
@@ -149,9 +149,9 @@ The repository is cloned and used as a source for configuration files.`,
149149
Examples: []cli.Example{
150150
{
151151
Codes: []cli.Code{
152-
{Title: "Cli", Source: "--providers-git-repositories[0]-url https://github.com/foo/foo.git"},
153-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES[0]_URL=https://github.com/foo/foo.git"},
154-
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git", Type: "yaml"},
152+
{Title: "CLI", Source: "--providers-git-repositories[0]-url https://github.com/foo/foo.git"},
153+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES[0]_URL=https://github.com/foo/foo.git"},
154+
{Title: "File", Source: "providers:\n git:\n repositories:\n - url: https://github.com/foo/foo.git", Language: "yaml"},
155155
},
156156
},
157157
},
@@ -164,9 +164,9 @@ Only the specified files are considered. This option can be used multiple times
164164
Examples: []cli.Example{
165165
{
166166
Codes: []cli.Code{
167-
{Title: "Cli", Source: "--providers-git-repositories[0]-file mokapi/api.json"},
168-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES[0]_FILE=mokapi/api.json"},
169-
{Title: "File", Source: "providers:\n git:\n repositories:\n - files: [mokapi/api.json]", Type: "yaml"},
167+
{Title: "CLI", Source: "--providers-git-repositories[0]-file mokapi/api.json"},
168+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES[0]_FILE=mokapi/api.json"},
169+
{Title: "File", Source: "providers:\n git:\n repositories:\n - files: [mokapi/api.json]", Language: "yaml"},
170170
},
171171
},
172172
},
@@ -179,9 +179,9 @@ This option is equivalent to using providers-git-repositories[<index>]-file mult
179179
Examples: []cli.Example{
180180
{
181181
Codes: []cli.Code{
182-
{Title: "Cli", Source: "--providers-git-repositories[0]-files mokapi/api.json mokapi/handler.js"},
183-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES[0]_FILES=mokapi/api.json mokapi/handler.js"},
184-
{Title: "File", Source: "providers:\n git:\n repositories:\n - files: [mokapi/api.json mokapi/handler.js]", Type: "yaml"},
182+
{Title: "CLI", Source: "--providers-git-repositories[0]-files mokapi/api.json mokapi/handler.js"},
183+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES[0]_FILES=mokapi/api.json mokapi/handler.js"},
184+
{Title: "File", Source: "providers:\n git:\n repositories:\n - files: [mokapi/api.json mokapi/handler.js]", Language: "yaml"},
185185
},
186186
},
187187
},
@@ -194,9 +194,9 @@ If at least one include pattern is specified, only files matching one of the pat
194194
Examples: []cli.Example{
195195
{
196196
Codes: []cli.Code{
197-
{Title: "Cli", Source: "--providers-git-repositories[0]-include mokapi/**/*.json"},
198-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES[0]_INCLUDE=mokapi/**/*.json"},
199-
{Title: "File", Source: "providers:\n git:\n repositories:\n - includes: [mokapi/**/*.json]", Type: "yaml"},
197+
{Title: "CLI", Source: "--providers-git-repositories[0]-include mokapi/**/*.json"},
198+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES[0]_INCLUDE=mokapi/**/*.json"},
199+
{Title: "File", Source: "providers:\n git:\n repositories:\n - includes: [mokapi/**/*.json]", Language: "yaml"},
200200
},
201201
},
202202
},
@@ -209,9 +209,9 @@ This option allows accessing private repositories hosted on GitHub by using cred
209209
Examples: []cli.Example{
210210
{
211211
Codes: []cli.Code{
212-
{Title: "Cli", Source: "--providers-git-repositories[0]-auth-github appId=12345,installationId=123456789,privateKey=2024-2-25.private-key.pem"},
213-
{Title: "Env", Source: "MOKAPI_GIT_REPOSITORIES[0]_AUTH_GITHUB=appId=12345,installationId=123456789,privateKey=2024-2-25.private-key.pem"},
214-
{Title: "File", Source: "providers:\n git:\n repositories:\n - auth:\n github:\n appId: 12345\n installationId: 12345\n privateKey: 2024-2-25.private-key.pem", Type: "yaml"},
212+
{Title: "CLI", Source: "--providers-git-repositories[0]-auth-github appId=12345,installationId=123456789,privateKey=2024-2-25.private-key.pem"},
213+
{Title: "Env", Source: "MOKAPI_PROVIDERS_GIT_REPOSITORIES[0]_AUTH_GITHUB=appId=12345,installationId=123456789,privateKey=2024-2-25.private-key.pem"},
214+
{Title: "File", Source: "providers:\n git:\n repositories:\n - auth:\n github:\n appId: 12345\n installationId: 12345\n privateKey: 2024-2-25.private-key.pem", Language: "yaml"},
215215
},
216216
},
217217
},

0 commit comments

Comments
 (0)