summaryrefslogtreecommitdiff
path: root/cmd/authelia-gen/cmd_docs_cli.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2022-09-16 14:21:05 +1000
committerGitHub <noreply@github.com>2022-09-16 14:21:05 +1000
commit9c72bc8977359ef5b79996d2b9bd41882438d11d (patch)
tree64eda7f64adc8f36bd2ec7f55f6a70b85702acb9 /cmd/authelia-gen/cmd_docs_cli.go
parent15110b732a4a24c9bd611477627bdd06291e10b2 (diff)
ci: gen github tmpl locales and commitlint (#3759)
This adds several automatic generators for Authelia docs etc.
Diffstat (limited to 'cmd/authelia-gen/cmd_docs_cli.go')
-rw-r--r--cmd/authelia-gen/cmd_docs_cli.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/cmd/authelia-gen/cmd_docs_cli.go b/cmd/authelia-gen/cmd_docs_cli.go
index 5e0c01bb7..e41b6f189 100644
--- a/cmd/authelia-gen/cmd_docs_cli.go
+++ b/cmd/authelia-gen/cmd_docs_cli.go
@@ -16,52 +16,56 @@ import (
func newDocsCLICmd() *cobra.Command {
cmd := &cobra.Command{
- Use: "cli",
+ Use: cmdUseDocsCLI,
Short: "Generate CLI docs",
RunE: docsCLIRunE,
DisableAutoGenTag: true,
}
- cmd.Flags().StringP("directory", "d", "./docs/content/en/reference/cli", "The directory to store the markdown in")
-
return cmd
}
func docsCLIRunE(cmd *cobra.Command, args []string) (err error) {
- var root string
+ var root, pathDocsCLIReference string
+
+ if root, err = cmd.Flags().GetString(cmdFlagRoot); err != nil {
+ return err
+ }
- if root, err = cmd.Flags().GetString("directory"); err != nil {
+ if pathDocsCLIReference, err = cmd.Flags().GetString(cmdFlagDocsCLIReference); err != nil {
return err
}
- if err = os.MkdirAll(root, 0775); err != nil {
+ fullPathDocsCLIReference := filepath.Join(root, pathDocsCLIReference)
+
+ if err = os.MkdirAll(fullPathDocsCLIReference, 0775); err != nil {
if !os.IsExist(err) {
return err
}
}
- if err = genCLIDoc(commands.NewRootCmd(), filepath.Join(root, "authelia")); err != nil {
+ if err = genCLIDoc(commands.NewRootCmd(), filepath.Join(fullPathDocsCLIReference, "authelia")); err != nil {
return err
}
- if err = genCLIDocWriteIndex(root, "authelia"); err != nil {
+ if err = genCLIDocWriteIndex(fullPathDocsCLIReference, "authelia"); err != nil {
return err
}
- if err = genCLIDoc(cmdscripts.NewRootCmd(), filepath.Join(root, "authelia-scripts")); err != nil {
+ if err = genCLIDoc(cmdscripts.NewRootCmd(), filepath.Join(fullPathDocsCLIReference, "authelia-scripts")); err != nil {
return err
}
- if err = genCLIDocWriteIndex(root, "authelia-scripts"); err != nil {
+ if err = genCLIDocWriteIndex(fullPathDocsCLIReference, "authelia-scripts"); err != nil {
return err
}
- if err = genCLIDoc(newRootCmd(), filepath.Join(root, "authelia-gen")); err != nil {
+ if err = genCLIDoc(newRootCmd(), filepath.Join(fullPathDocsCLIReference, cmdUseRoot)); err != nil {
return err
}
- if err = genCLIDocWriteIndex(root, "authelia-gen"); err != nil {
+ if err = genCLIDocWriteIndex(fullPathDocsCLIReference, cmdUseRoot); err != nil {
return err
}
@@ -69,6 +73,16 @@ func docsCLIRunE(cmd *cobra.Command, args []string) (err error) {
}
func genCLIDoc(cmd *cobra.Command, path string) (err error) {
+ if _, err = os.Stat(path); err != nil && !os.IsNotExist(err) {
+ return err
+ }
+
+ if err == nil || !os.IsNotExist(err) {
+ if err = os.RemoveAll(path); err != nil {
+ return fmt.Errorf("failed to remove docs: %w", err)
+ }
+ }
+
if err = os.Mkdir(path, 0755); err != nil {
if !os.IsExist(err) {
return err