Skip to content

Commit

Permalink
add gen docs build flag
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijitWakchaure committed Aug 13, 2022
1 parent cbaf8a4 commit 0637fb3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
12 changes: 6 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

GEN_DOCS="true"
GEN_DOCS="false"

APP_NAME="run-flogo-app"
APP_VERSION=`cat VERSION`
Expand All @@ -10,13 +10,13 @@ echo "Building binaries for ${APP_NAME}-${APP_VERSION}"

export CGO_ENABLED=0

rm -f dist/*
rm -rf dist/*

DOC_TAG=$([ "$GEN_DOCS" = "true" ] && echo "-tags=docs" || echo "")
DOC_TAG=$([ "$GEN_DOCS" = "true" ] && echo "-tags docs" || echo "")
[ "$GEN_DOCS" = "true" ] && echo "Using DOC_TAG: ${DOC_TAG}"
echo "### Building for platform: linux/amd64"
GOOS=linux GOARCH=amd64 go build ${DOC_TAG} -ldflags "-s -w" -o dist/${APP_NAME}-linux_amd64
GOOS=linux GOARCH=amd64 go build ${DOC_TAG} -ldflags "${LDFLAGS}" -o dist/${APP_NAME}-linux_amd64
echo "### Building for platform: windows/amd64"
GOOS=windows GOARCH=amd64 go build ${DOC_TAG} -ldflags "-s -w" -o dist/${APP_NAME}-windows_amd64.exe
GOOS=windows GOARCH=amd64 go build ${DOC_TAG} -ldflags "${LDFLAGS}" -o dist/${APP_NAME}-windows_amd64.exe
echo "### Building for platform: darwin/amd64"
GOOS=darwin GOARCH=amd64 go build ${DOC_TAG} -ldflags "-s -w" -o dist/${APP_NAME}-darwin_amd64
GOOS=darwin GOARCH=amd64 go build ${DOC_TAG} -ldflags "${LDFLAGS}" -o dist/${APP_NAME}-darwin_amd64
13 changes: 13 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build docs
// +build docs

package cmd

import (
"fmt"
)

func init() {
fmt.Println("Initializing docs...")
GENDOCS = true
}
24 changes: 23 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
)

var a *app.App

// GENDOCS ...
var GENDOCS bool

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -45,8 +47,18 @@ var rootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if GENDOCS {
err := os.RemoveAll("./docs")
if err != nil {
fmt.Printf("E> Failed to remove old docs! Error: %s\n", err.Error())
os.Exit(1)
}
err = os.Mkdir("./docs", 0744)
if err != nil {
fmt.Printf("E> Failed to create docs dir! Error: %s\n", err.Error())
os.Exit(1)
}
fmt.Println("i> Generating docs...")
err := doc.GenMarkdownTree(rootCmd, "./docs")
err = doc.GenMarkdownTree(rootCmd, "./docs")
if err != nil {
fmt.Printf("E> Failed to generate markdown docs! Error: %s\n", err.Error())
os.Exit(1)
Expand All @@ -55,6 +67,16 @@ func Execute() {
Title: config.AppName,
Section: "3",
}
err = os.RemoveAll("./manpages")
if err != nil {
fmt.Printf("E> Failed to remove old manpages! Error: %s\n", err.Error())
os.Exit(1)
}
err = os.Mkdir("./manpages", 0744)
if err != nil {
fmt.Printf("E> Failed to create manpages dir! Error: %s\n", err.Error())
os.Exit(1)
}
err = doc.GenManTree(rootCmd, header, "./manpages")
if err != nil {
fmt.Printf("E> Failed to generate man pages! Error: %s\n", err.Error())
Expand Down

0 comments on commit 0637fb3

Please sign in to comment.