Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for the generation of cli docs for harbor #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/harbor/root/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ harbor help
cobra.OnInitialize(InitConfig)

root.PersistentFlags().StringVarP(&output, "output-format", "o", "", "Output format. One of: json|yaml")
root.PersistentFlags().StringVar(&cfgFile, "config", utils.DefaultConfigPath, "config file (default is $HOME/.harbor/config.yaml)")
root.PersistentFlags().StringVar(&cfgFile, "config", utils.DefaultConfigPath, "config file")
root.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")

err := viper.BindPFlag("output-format", root.PersistentFlags().Lookup("output-format"))
Expand All @@ -104,6 +104,7 @@ harbor help
root.AddCommand(
versionCommand(),
LoginCommand(),
GenerateDocs(),
project.Project(),
registry.Registry(),
repositry.Repository(),
Expand Down
71 changes: 71 additions & 0 deletions cmd/harbor/root/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package root

import (
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
func GenerateDocs() *cobra.Command {

cmd := &cobra.Command{
Use: "gen-docs",
Short: "Generate documentation for Harbor CLI",
Long: `Generate documentation for Harbor CLI`,
Hidden: true,
Run: func (cmd *cobra.Command, args []string) {
path, err:= cmd.Flags().GetString("dir")
if err != nil {
log.Fatal(err)
}
if path == "" {
path = "docs"
}
err = os.MkdirAll(path, os.ModePerm)
if err != nil {
log.Fatal(err)
}
err = doc.GenYamlTree(cmd.Root(), path)
if err != nil {
log.Fatal(err)
}
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
err = replaceHomeDirWithEnvVar(path, homeDir, "$HOME")
if err != nil {
log.Fatal(err)
}

log.Infof("Documentation generated in %s", path)
},
}

cmd.Flags().String("dir", "", "Directory to generate documentation in")
return cmd

}

func replaceHomeDirWithEnvVar(path, homeDir, envVar string) error {
return filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
content, err := os.ReadFile(filePath)
if err != nil {
return err
}
updatedContent := strings.ReplaceAll(string(content), homeDir, envVar)
err = os.WriteFile(filePath, []byte(updatedContent), info.Mode())
if err != nil {
return err
}
}
return nil
})
}
33 changes: 33 additions & 0 deletions docs/harbor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: harbor
synopsis: Official Harbor CLI
description: Official Harbor CLI
options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: help
shorthand: h
default_value: "false"
usage: help for harbor
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: |4
// Base command:
harbor

// Display help about the command:
harbor help
see_also:
- harbor artifact - Manage artifacts
- harbor completion - Generate the autocompletion script for the specified shell
- harbor login - Log in to Harbor registry
- harbor project - Manage projects and assign resources to them
- harbor registry - Manage registries
- harbor repo - Manage repositories
- harbor user - Manage users
- harbor version - Version of Harbor CLI
27 changes: 27 additions & 0 deletions docs/harbor_artifact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: harbor artifact
synopsis: Manage artifacts
description: Manage artifacts in Harbor Repository
options:
- name: help
shorthand: h
default_value: "false"
usage: help for artifact
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: ' harbor artifact list'
see_also:
- harbor - Official Harbor CLI
- harbor artifact delete - delete an artifact
- harbor artifact info - Get info of an artifact
- harbor artifact list - list artifacts within a repository
- harbor artifact scan - Scan an artifact
- harbor artifact tags - Manage tags of an artifact
21 changes: 21 additions & 0 deletions docs/harbor_artifact_delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: harbor artifact delete
synopsis: delete an artifact
usage: harbor artifact delete [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for delete
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
see_also:
- harbor artifact - Manage artifacts
23 changes: 23 additions & 0 deletions docs/harbor_artifact_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: harbor artifact info
synopsis: Get info of an artifact
description: Get info of an artifact
usage: harbor artifact info [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for info
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact info <project>/<repository>/<reference>
see_also:
- harbor artifact - Manage artifacts
21 changes: 21 additions & 0 deletions docs/harbor_artifact_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: harbor artifact list
synopsis: list artifacts within a repository
usage: harbor artifact list [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for list
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
see_also:
- harbor artifact - Manage artifacts
24 changes: 24 additions & 0 deletions docs/harbor_artifact_scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: harbor artifact scan
synopsis: Scan an artifact
description: Scan an artifact in Harbor Repository
options:
- name: help
shorthand: h
default_value: "false"
usage: help for scan
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact scan start <project>/<repository>/<reference>
see_also:
- harbor artifact - Manage artifacts
- harbor artifact scan start - Start a scan of an artifact
- harbor artifact scan stop - Stop a scan of an artifact
23 changes: 23 additions & 0 deletions docs/harbor_artifact_scan_start.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: harbor artifact scan start
synopsis: Start a scan of an artifact
description: Start a scan of an artifact in Harbor Repository
usage: harbor artifact scan start [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for start
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact scan start <project>/<repository>/<reference>
see_also:
- harbor artifact scan - Scan an artifact
23 changes: 23 additions & 0 deletions docs/harbor_artifact_scan_stop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: harbor artifact scan stop
synopsis: Stop a scan of an artifact
description: Stop a scan of an artifact in Harbor Repository
usage: harbor artifact scan stop [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for stop
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact scan stop <project>/<repository>/<reference>
see_also:
- harbor artifact scan - Scan an artifact
24 changes: 24 additions & 0 deletions docs/harbor_artifact_tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: harbor artifact tags
synopsis: Manage tags of an artifact
options:
- name: help
shorthand: h
default_value: "false"
usage: help for tags
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: ' harbor artifact tags list <project>/<repository>/<reference>'
see_also:
- harbor artifact - Manage artifacts
- harbor artifact tags create - Create a tag of an artifact
- harbor artifact tags delete - Delete a tag of an artifact
- harbor artifact tags list - List tags of an artifact
22 changes: 22 additions & 0 deletions docs/harbor_artifact_tags_create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: harbor artifact tags create
synopsis: Create a tag of an artifact
usage: harbor artifact tags create [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for create
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact tags create <project>/<repository>/<reference> <tag>
see_also:
- harbor artifact tags - Manage tags of an artifact
22 changes: 22 additions & 0 deletions docs/harbor_artifact_tags_delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: harbor artifact tags delete
synopsis: Delete a tag of an artifact
usage: harbor artifact tags delete [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for delete
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact tags delete <project>/<repository>/<reference> <tag>
see_also:
- harbor artifact tags - Manage tags of an artifact
22 changes: 22 additions & 0 deletions docs/harbor_artifact_tags_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: harbor artifact tags list
synopsis: List tags of an artifact
usage: harbor artifact tags list [flags]
options:
- name: help
shorthand: h
default_value: "false"
usage: help for list
inherited_options:
- name: config
default_value: $HOME/.config/harbor/config.yaml
usage: config file
- name: output-format
shorthand: o
usage: 'Output format. One of: json|yaml'
- name: verbose
shorthand: v
default_value: "false"
usage: verbose output
example: harbor artifact tags list <project>/<repository>/<reference>
see_also:
- harbor artifact tags - Manage tags of an artifact
Loading
Loading