Skip to content

Commit

Permalink
handle multiple files and no files
Browse files Browse the repository at this point in the history
  • Loading branch information
mhristof committed Dec 7, 2020
1 parent fede587 commit 2385910
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,45 @@ var version = "devel"
var rootCmd = &cobra.Command{
Use: "githubactions-docs",
Short: "Generate documentation for Github Actions similar to terraform-docs",
Args: cobra.ArbitraryArgs,
Version: version,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Verbose(cmd)
var files []string

if _, err := os.Stat(args[0]); os.IsNotExist(err) {
panic(fmt.Sprintf("Error, file %s does not exist", args[0]))
}
files = append(files, args...)

data, err := ioutil.ReadFile(args[0])
if err != nil {
log.WithFields(log.Fields{
"err": err,
"args[0]": args[0],
}).Error("Could not load file")
if len(args) == 0 {
files = append(files, "action.yml")
}

cfg, err := action.Load(data)
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("Could not decode action file")
}
for _, file := range files {
if _, err := os.Stat(file); os.IsNotExist(err) {
log.WithFields(log.Fields{
"file": file,
}).Error("File not found")
continue
}

data, err := ioutil.ReadFile(file)
if err != nil {
log.WithFields(log.Fields{
"err": err,
"file": file,
}).Error("Could not load file")
continue
}

fmt.Println(cfg.Markdown())
cfg, err := action.Load(data)
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("Could not decode action file")
continue
}

fmt.Println(cfg.Markdown())
}
},
}

Expand Down

0 comments on commit 2385910

Please sign in to comment.