Code cleanup for public release

main
Nick Dumas 2 years ago
parent 499a5e6b6d
commit d24ceeac69

@ -5,6 +5,7 @@ package cmd
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
@ -18,7 +19,6 @@ var (
format string
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
TraverseChildren: true,
Use: "obp",
@ -33,8 +33,7 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
@ -42,24 +41,32 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "~/.obp.toml", "config file")
rootCmd.PersistentFlags().StringVar(&vault, "vault", "", "vault root directory")
rootCmd.MarkPersistentFlagRequired("vault")
err := rootCmd.MarkPersistentFlagRequired("vault")
if err != nil {
log.Panicln("error setting vault flag as required")
}
rootCmd.PersistentFlags().StringVar(&format, "format", "markdown", "output format [markdown, json, csv]")
rootCmd.MarkPersistentFlagRequired("format")
viper.BindPFlag("format", rootCmd.PersistentFlags().Lookup("format"))
viper.BindPFlag("vault", rootCmd.PersistentFlags().Lookup("vault"))
err = rootCmd.MarkPersistentFlagRequired("format")
if err != nil {
log.Panicln("error setting format flag as required")
}
err = viper.BindPFlag("format", rootCmd.PersistentFlags().Lookup("format"))
if err != nil {
log.Panicln("error binding viper to format flag")
}
// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
err = viper.BindPFlag("vault", rootCmd.PersistentFlags().Lookup("vault"))
if err != nil {
log.Panicln("error binding viper to vault flag")
}
// rootCmd.SetHelpFunc(gloss.CharmHelp)
// rootCmd.SetUsageFunc(gloss.CharmUsage)

@ -10,6 +10,10 @@ import (
"gopkg.in/yaml.v3"
)
// Validate accepts a Markdown file as input via the Reader
// and parses the frontmatter present, if any. It then
// applies the schema fetched from schemaURL against the
// decoded YAML.
func Validate(schemaURL string, r io.Reader) error {
var m interface{}
@ -42,6 +46,10 @@ func recurseDetails(detailed jsonschema.Detailed, acc map[string]jsonschema.Deta
return acc
}
// PrettyDetails takes error output from jsonschema.Validate
// and pretty-prints it to stdout.
//
// Supported formats are: JSON, Markdown
func PrettyDetails(w io.Writer, format string, details jsonschema.Detailed, filename string) error {
// acc := make([]jsonschema.Detailed, 0)
acc := make(map[string]jsonschema.Detailed)

Loading…
Cancel
Save