cmd
import "github.com/b13rg/croissant-go/cmd"
Defines the cli-interface commands available to the user.
Test a croissant file
Output package version info.
Index
- Variables
- func Colorize(input interface{}, colorNum int, disabled bool) string
- func ConfigureLogger(debug bool)
- func Execute(ver string)
- func InitConfig()
- func ProfilingFinalizer()
- func ProfilingInitializer()
- func SetupLogger(enableColor bool) zerolog.Logger
- type CmdRootOptions
- type Stamp
Variables
RootCmd represents the base command when called without any subcommands.
var RootCmd = &cobra.Command{
Use: "croissant",
Short: "A cli for Croissant files",
Long: `A simple cli for interacting with 🥐 Croissant dataset files.`,
}
var TestCmd = &cobra.Command{
Use: "test path",
Short: "Test loading and validating a Croissant file",
Long: `Test loading and validating a Croissant file`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 || args[0] == "" {
log.Logger.Fatal().Msg("invalid path param")
}
dataSet, err := croissant.NewDataSetFromPath(args[0])
if err != nil {
log.Logger.Fatal().AnErr("DatasetFromPath", err).Msg("error loading file")
}
log.Logger.Info().Str("name", dataSet.Name).Msg("Dataset name")
listWarn, listErr := dataSet.Validate()
for _, w := range listWarn {
log.Logger.Warn().AnErr("validate", w)
}
for _, e := range listErr {
log.Logger.Error().AnErr("validate", e)
}
err = dataSet.WriteToFile("./out.json")
if err != nil {
log.Logger.Error().AnErr("Marshalling", err).Msg("err")
}
},
}
Print out versions of packages in use. Chore() - Updated manually.
var VersionCmd = &cobra.Command{
Use: "version",
Short: "Get version",
Long: `Get the current version of tool`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(RootCmd.Use + "+ Version: " + version)
info, ok := debug.ReadBuildInfo()
if !ok {
log.Fatal().Msg("could not read build info")
}
stamp := retrieveStamp(info)
fmt.Printf(" Built with %s on %s\n", stamp.InfoGoCompiler, stamp.InfoBuildTime)
fmt.Printf(" VCS revision: %s\n", stamp.VCSRevision)
fmt.Printf(" Go version %s, GOOS %s, GOARCH %s\n", info.GoVersion, stamp.InfoGOOS, stamp.InfoGOARCH)
fmt.Print(" Dependencies:\n")
for _, mod := range retrieveDepends(info) {
fmt.Printf(" %s\n", mod)
}
},
}
func Colorize
func Colorize(input interface{}, colorNum int, disabled bool) string
Colorize function from zerolog console.go file to replicate their coloring functionality. Source: https://github.com/rs/zerolog/blob/a21d6107dcda23e36bc5cfd00ce8fdbe8f3ddc23/console.go#L389 Replicated here because it's a private function.
func ConfigureLogger
func ConfigureLogger(debug bool)
func Execute
func Execute(ver string)
Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func InitConfig
func InitConfig()
InitConfig reads in config file and ENV variables if set.
func ProfilingFinalizer
func ProfilingFinalizer()
Stop profiling and write cpu and memory profiling files if configured.
func ProfilingInitializer
func ProfilingInitializer()
Sets up program profiling.
func SetupLogger
func SetupLogger(enableColor bool) zerolog.Logger
Configure zerolog with some defaults and cleanup error formatting.
type CmdRootOptions
Default options that are available to all commands.
type CmdRootOptions struct {
// log more information about what the tool is doing. Overrides --loglevel
Debug bool
// set log level
LogLevel string
// enable colorized output (default true). Set to false to disable")
Color bool
// Profiling output directory. Only captured if set.
ProfilingDir string
// CPU profiling output file handle.
ProfilingCPUFile *os.File
}
var RootConfig CmdRootOptions
type Stamp
type Stamp struct {
InfoGoVersion string
InfoGoCompiler string
InfoGOARCH string
InfoGOOS string
InfoBuildTime string
VCSRevision string
}