Skip to content

Commit

Permalink
Removed unused code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack tonye authored and Jack tonye committed Nov 6, 2021
1 parent 855a448 commit 6b997b9
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 316 deletions.
134 changes: 134 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ package cmd
import (
"bytes"
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"io/ioutil"
"log"
"os"
"sort"
"strconv"
"strings"
)

var InputsHeader = "## Inputs"
Expand Down Expand Up @@ -72,6 +76,136 @@ func (a *Action) RenderToOutput() {
a.renderToOutput()
}

func (a *Action) renderToOutput() {
var err error
inputTableOutput := &strings.Builder{}

if len(a.Inputs) > 0 {
_, err = fmt.Fprintln(inputTableOutput, inputAutoDocStart)
if err != nil {
cobra.CheckErr(err)
}

inputTable := tablewriter.NewWriter(inputTableOutput)
inputTable.SetHeader([]string{"Input", "Required", "Default", "Description"})
inputTable.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
inputTable.SetCenterSeparator("|")

keys := make([]string, 0, len(a.Inputs))
for k := range a.Inputs {
keys = append(keys, k)
}
sort.Strings(keys)

for _, key := range keys {
row := []string{key, strconv.FormatBool(a.Inputs[key].Required), a.Inputs[key].Default, a.Inputs[key].Description}
inputTable.Append(row)
}

_, err = fmt.Fprintln(inputTableOutput)
if err != nil {
cobra.CheckErr(err)
}

inputTable.Render()

_, err = fmt.Fprintln(inputTableOutput)
if err != nil {
cobra.CheckErr(err)
}

_, err = fmt.Fprint(inputTableOutput, inputAutoDocEnd)
if err != nil {
cobra.CheckErr(err)
}
}

outputTableOutput := &strings.Builder{}

if len(a.Outputs) > 0 {
_, err = fmt.Fprintln(outputTableOutput, outputAutoDocStart)
if err != nil {
cobra.CheckErr(err)
}

outputTable := tablewriter.NewWriter(outputTableOutput)
outputTable.SetHeader([]string{"Output", "Description", "Value"})
outputTable.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
outputTable.SetCenterSeparator("|")

keys := make([]string, 0, len(a.Outputs))
for k := range a.Outputs {
keys = append(keys, k)
}
sort.Strings(keys)

for _, key := range keys {
row := []string{key, a.Outputs[key].Description, a.Outputs[key].Value}
outputTable.Append(row)
}

_, err = fmt.Fprintln(outputTableOutput)
if err != nil {
cobra.CheckErr(err)
}

outputTable.Render()

_, err = fmt.Fprintln(outputTableOutput)
if err != nil {
cobra.CheckErr(err)
}

_, err = fmt.Fprint(outputTableOutput, outputAutoDocEnd)
if err != nil {
cobra.CheckErr(err)
}
}

input, err := ioutil.ReadFile(outputFileName)

if err != nil {
cobra.CheckErr(err)
}

var output = []byte("")

hasInputsData, inputStartIndex, inputEndIndex := HasBytesInBetween(
input,
[]byte(InputsHeader),
[]byte(inputAutoDocEnd),
)

if hasInputsData {
inputsStr := fmt.Sprintf("%s\n\n%v", InputsHeader, inputTableOutput.String())
output = ReplaceBytesInBetween(input, inputStartIndex, inputEndIndex, []byte(inputsStr))
} else {
inputsStr := fmt.Sprintf("%s\n\n%v", InputsHeader, inputTableOutput.String())
output = bytes.Replace(input, []byte(InputsHeader), []byte(inputsStr), -1)
}

hasOutputsData, outputStartIndex, outputEndIndex := HasBytesInBetween(
output,
[]byte(OutputsHeader),
[]byte(outputAutoDocEnd),
)

if hasOutputsData {
outputsStr := fmt.Sprintf("%s\n\n%v", OutputsHeader, outputTableOutput.String())
output = ReplaceBytesInBetween(output, outputStartIndex, outputEndIndex, []byte(outputsStr))
} else {
outputsStr := fmt.Sprintf("%s\n\n%v", OutputsHeader, outputTableOutput.String())
output = bytes.Replace(output, []byte(OutputsHeader), []byte(outputsStr), -1)
}

if len(output) > 0 {
if err = ioutil.WriteFile(outputFileName, output, 0666); err != nil {
cobra.CheckErr(err)
}
}
}


// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "auto-doc",
Expand Down
159 changes: 0 additions & 159 deletions cmd/root_unix.go

This file was deleted.

0 comments on commit 6b997b9

Please sign in to comment.