Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit f354e65

Browse files
authored
Merge pull request #737 from jcsirot/markdown-cli-examples
Use markdown in CLI examples for automatic documentation generation
2 parents 7fc0612 + 8e29667 commit f354e65

File tree

7 files changed

+47
-35
lines changed

7 files changed

+47
-35
lines changed

internal/commands/build/build.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ type buildOptions struct {
4545
noResolveImage bool
4646
}
4747

48+
const buildExample = `- $ docker app run --name myrunningapp myrepo/myapp:mytag
49+
- $ docker app run 34be4a0c5f50 --name myrunningapp`
50+
4851
func Cmd(dockerCli command.Cli) *cobra.Command {
4952
var opts buildOptions
5053
cmd := &cobra.Command{
51-
Use: "build [OPTIONS] BUILD_PATH",
52-
Short: "Build an App image from an App definition (.dockerapp)",
53-
Example: `$ docker app build .
54-
$ docker app build . -f myapp.dockerapp -t myrepo/myapp:1.0.0`,
55-
Args: cli.ExactArgs(1),
54+
Use: "build [OPTIONS] BUILD_PATH",
55+
Short: "Build an App image from an App definition (.dockerapp)",
56+
Example: buildExample,
57+
Args: cli.ExactArgs(1),
5658
RunE: func(cmd *cobra.Command, args []string) error {
5759
return runBuild(dockerCli, args[0], opts)
5860
},

internal/commands/image/inspect.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import (
1717
"github.com/spf13/cobra"
1818
)
1919

20+
const inspectExample = `- $ docker app image inspect myapp
21+
- $ docker app image inspect myapp:1.0.0
22+
- $ docker app image inspect myrepo/myapp:1.0.0
23+
- $ docker app image inspect 34be4a0c5f50`
24+
2025
type inspectOptions struct {
2126
pretty bool
2227
cliopts.InstallerContextOptions
@@ -34,13 +39,10 @@ func muteDockerCli(dockerCli command.Cli) func() {
3439
func inspectCmd(dockerCli command.Cli) *cobra.Command {
3540
var opts inspectOptions
3641
cmd := &cobra.Command{
37-
Use: "inspect [OPTIONS] APP_IMAGE",
38-
Short: "Display detailed information about an App image",
39-
Example: `$ docker app image inspect myapp
40-
$ docker app image inspect myapp:1.0.0
41-
$ docker app image inspect myrepo/myapp:1.0.0
42-
$ docker app image inspect 34be4a0c5f50`,
43-
Args: cli.ExactArgs(1),
42+
Use: "inspect [OPTIONS] APP_IMAGE",
43+
Short: "Display detailed information about an App image",
44+
Example: inspectExample,
45+
Args: cli.ExactArgs(1),
4446
RunE: func(cmd *cobra.Command, args []string) error {
4547
return runInspect(dockerCli, args[0], opts)
4648
},

internal/commands/image/rm.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15+
const rmExample = `- $ docker app image rm myapp
16+
- $ docker app image rm myapp:1.0.0
17+
- $ docker app image rm myrepo/myapp@sha256:c0de...
18+
- $ docker app image rm 34be4a0c5f50`
19+
1520
func rmCmd() *cobra.Command {
1621
return &cobra.Command{
1722
Short: "Remove an App image",
1823
Use: "rm APP_IMAGE [APP_IMAGE...]",
1924
Aliases: []string{"remove"},
2025
Args: cli.RequiresMinArgs(1),
21-
Example: `$ docker app image rm myapp
22-
$ docker app image rm myapp:1.0.0
23-
$ docker app image rm myrepo/myapp@sha256:c0de...
24-
$ docker app image rm 34be4a0c5f50`,
26+
Example: rmExample,
2527
RunE: func(cmd *cobra.Command, args []string) error {
2628
appstore, err := store.NewApplicationStore(config.Dir())
2729
if err != nil {

internal/commands/image/tag.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15+
const tagExample = `- $ docker app image tag myapp myrepo/myapp:mytag
16+
- $ docker app image tag myapp:tag myrepo/mynewapp:mytag
17+
- $ docker app image tag 34be4a0c5f50 myrepo/mynewapp:mytag`
18+
1519
func tagCmd() *cobra.Command {
1620
cmd := &cobra.Command{
17-
Short: "Create a new tag from an App image",
18-
Use: "tag SOURCE_APP_IMAGE[:TAG] TARGET_APP_IMAGE[:TAG]",
19-
Example: `$ docker app image tag myapp myrepo/myapp:mytag
20-
$ docker app image tag myapp:tag myrepo/mynewapp:mytag
21-
$ docker app image tag 34be4a0c5f50 myrepo/mynewapp:mytag`,
22-
Args: cli.ExactArgs(2),
21+
Short: "Create a new tag from an App image",
22+
Use: "tag SOURCE_APP_IMAGE[:TAG] TARGET_APP_IMAGE[:TAG]",
23+
Example: tagExample,
24+
Args: cli.ExactArgs(2),
2325
RunE: func(cmd *cobra.Command, args []string) error {
2426
appstore, err := store.NewApplicationStore(config.Dir())
2527
if err != nil {

internal/commands/init.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ var (
1313
initComposeFile string
1414
)
1515

16+
const initExample = `- $ docker app init myapp
17+
- $ docker app init myapp --compose-file docker-compose.yml`
18+
1619
func initCmd(dockerCli command.Cli) *cobra.Command {
1720
cmd := &cobra.Command{
18-
Use: "init [OPTIONS] APP_DEFINITION",
19-
Short: "Initialize an App definition",
20-
Example: `$ docker app init myapp
21-
$ docker app init myapp --compose-file docker-compose.yml`,
22-
Args: cli.ExactArgs(1),
21+
Use: "init [OPTIONS] APP_DEFINITION",
22+
Short: "Initialize an App definition",
23+
Example: initExample,
24+
Args: cli.ExactArgs(1),
2325
RunE: func(cmd *cobra.Command, args []string) error {
2426
created, err := packager.Init(dockerCli.Err(), args[0], initComposeFile)
2527
if err != nil {

internal/commands/inspect.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import (
1717
"github.com/spf13/cobra"
1818
)
1919

20+
const inspectExample = `- $ docker app inspect my-running-app
21+
- $ docker app inspect my-running-app:1.0.0`
22+
2023
type inspectOptions struct {
2124
credentialOptions
2225
cliopts.InstallerContextOptions
@@ -28,11 +31,10 @@ type inspectOptions struct {
2831
func inspectCmd(dockerCli command.Cli) *cobra.Command {
2932
var opts inspectOptions
3033
cmd := &cobra.Command{
31-
Use: "inspect [OPTIONS] RUNNING_APP",
32-
Short: "Shows status, metadata, parameters and the list of services of a running App",
33-
Example: `$ docker app inspect my-running-app
34-
$ docker app inspect my-running-app:1.0.0`,
35-
Args: cli.ExactArgs(1),
34+
Use: "inspect [OPTIONS] RUNNING_APP",
35+
Short: "Shows status, metadata, parameters and the list of services of a running App",
36+
Example: inspectExample,
37+
Args: cli.ExactArgs(1),
3638
RunE: func(cmd *cobra.Command, args []string) error {
3739
return runInspect(dockerCli, firstOrEmpty(args), opts)
3840
},

internal/commands/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ type runOptions struct {
3535

3636
const longDescription = `Run an App from an App image.`
3737

38-
const example = `$ docker app run --name myrunningapp myrepo/myapp:mytag
39-
$ docker app run 34be4a0c5f50 --name myrunningapp`
38+
const runExample = `- $ docker app run --name myrunningapp myrepo/myapp:mytag
39+
- $ docker app run 34be4a0c5f50 --name myrunningapp`
4040

4141
func runCmd(dockerCli command.Cli) *cobra.Command {
4242
var opts runOptions
@@ -46,7 +46,7 @@ func runCmd(dockerCli command.Cli) *cobra.Command {
4646
Aliases: []string{"deploy"},
4747
Short: "Run an App from an App image",
4848
Long: longDescription,
49-
Example: example,
49+
Example: runExample,
5050
RunE: func(cmd *cobra.Command, args []string) error {
5151
if opts.cnabBundle != "" && len(args) != 0 {
5252
return errors.Errorf(

0 commit comments

Comments
 (0)