Skip to content

Commit

Permalink
Updated the root command.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Oct 24, 2021
1 parent 66fc7fd commit d3ab089
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 129 deletions.
40 changes: 38 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,36 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"io/ioutil"
"log"
"os"
)

var actionFileName string
var outputFileName string

type Action struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Inputs yaml.Node `yaml:"inputs,omitempty"`
Outputs yaml.Node `yaml:"outputs,omitempty"`
}

func (a *Action) getAction() *Action {
actionYaml, err := ioutil.ReadFile(actionFileName)
if err != nil {
cobra.CheckErr(err)
}

err = yaml.Unmarshal(actionYaml, a)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}

return a
}

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "auto-doc",
Expand All @@ -43,8 +67,20 @@ var rootCmd = &cobra.Command{
return
}

fmt.Printf("Working on %s \n", outputFileName)
fmt.Printf("Action file: %s \n", actionFileName)
var action Action
action.getAction()

fmt.Println(action)

readMe, err := ioutil.ReadFile(outputFileName)

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

for _, line := range readMe {
fmt.Printf("%b\n", line)
}
},
}

Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/tj-actions/auto-doc

go 1.14

require (
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
)
require github.com/spf13/cobra v1.2.1

0 comments on commit d3ab089

Please sign in to comment.