Skip to content

Commit

Permalink
refactor: handle the errors when generating the documentation of the …
Browse files Browse the repository at this point in the history
…commands

Signed-off-by: Cosmin Cojocar <[email protected]>
  • Loading branch information
ccojocar authored and jenkins-x-bot committed Jan 2, 2020
1 parent 6bc9513 commit 24fc7d9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/cmd/create/create_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/jenkins-x/jx/pkg/cmd/create/options"
"github.com/pkg/errors"

"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/util"
Expand Down Expand Up @@ -79,29 +80,27 @@ func NewCmdCreateDocs(commonOpts *opts.CommonOptions) *cobra.Command {
func (o *CreateDocsOptions) Run(jxCommand *cobra.Command) error {
dir := o.Dir

exists, _ := util.FileExists(dir)
exists, err := util.FileExists(dir)
if err != nil {
return errors.Wrapf(err, "checking whether the file %q exists", dir)
}
if !exists {
err := os.Mkdir(dir, util.DefaultWritePermissions)
if err != nil {
return fmt.Errorf("failed to create %s: %s", dir, err)
}
}

now := time.Now().Format(time.RFC3339)
prepender := func(filename string) string {
name := filepath.Base(filename)
base := strings.TrimSuffix(name, path.Ext(name))
url := "/commands/" + strings.ToLower(base) + "/"
return fmt.Sprintf(gendocFrontmatterTemplate, now, strings.Replace(base, "_", " ", -1), base, url)
}

linkHandler := func(name string) string {
base := strings.TrimSuffix(name, path.Ext(name))
return "/commands/" + strings.ToLower(base) + "/"
}

//jww.FEEDBACK.Println("Generating Hugo command-line documentation in", gendocdir, "...")
doc.GenMarkdownTreeCustom(jxCommand, dir, prepender, linkHandler)
//jww.FEEDBACK.Println("Done.")

return nil
return doc.GenMarkdownTreeCustom(jxCommand, dir, prepender, linkHandler)
}

0 comments on commit 24fc7d9

Please sign in to comment.