Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Root is the root of the commands. Root = &cobra.Command{ Use: "csvtojson", SilenceErrors: true, SilenceUsage: true, Short: "csvtojson is a simple command line tool to parse CSV files and convert them to JSON", Long: `csvtojson is a simple command line tool to parse CSV files and convert them to JSON. More documentation at https://go.krishnaiyer.dev/csvtojson`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { err := manager.Unmarshal(config) if err != nil { panic(err) } return nil }, Run: func(cmd *cobra.Command, args []string) { logger, err := zephyrus.New(context.Background(), config.Debug) if err != nil { log.Fatal(err.Error()) } defer logger.Clean() ctx := zephyrus.NewContextWithLogger(context.Background(), logger) raw, err := ioutil.ReadFile(config.CSVFile) if err != nil { logger.Fatal(err.Error()) } loggerCtx := zephyrus.NewContextWithLogger(ctx, logger) csv, err := csv.New(loggerCtx, raw, config.Values) if err != nil { logger.Fatal(err.Error()) } var marshaled []byte if config.YAML { marshaled, err = csv.MarshalYAML() } else { marshaled, err = csv.MarshalJSON() } if err != nil { logger.Fatal(err.Error()) } file := os.Stdout if config.OutFile != "" { file, err = os.Create(config.OutFile) if err != nil { logger.Fatal(err.Error()) } } _, err = file.Write(marshaled) if err != nil { logger.Fatal(err.Error()) } }, } )
Functions ¶
Types ¶
This section is empty.