themalkolm / venom Goto Github PK
View Code? Open in Web Editor NEW๐ Make viper and cobra more venomous!
License: MIT License
๐ Make viper and cobra more venomous!
License: MIT License
func LogObject(in interface{}, output string, lvl logrus.Level) error {
w := logrus.StandardLogger().WriterLevel(lvl)
defer w.Close()
return venom.WriteObject(in, venom.Format(output), w)
}
Something like this. A way to write object to log.
Not sure we need this.. simply passing bytes to a function so it writes them to the writer we pass to this function as well.. weeird.
Not every tools wants to have this short flag being stolen by venom.
type Flager interface {
Flags() *pflag.FlagSet
}
Maybe not even only for inners structs. Maybe for any struct at all i.e. if it is available - use it instead of introspection.
e.g.
func (c *FooConfig) Validate() (err *multierror.Error) {
...
return err
}
If we define this method it should be invoked during flag parsing to ensure the config is valid e.g.
var cfg FooConfig
err := venom.Validate(&cfg)
This will go and recursively run Validate
for all flag-tagged struct etc.
It would be nice to automatically generate config structure for any command e.g.
var RootCmd = &cobra.Command{
Use: "foobar",
...
func init() {
//
// You need to define flags as usual.
//
RootCmd.PersistentFlags().String("foo", "", "Some foonees must be set")
RootCmd.PersistentFlags().String("foo-bar", "", "Some barness must be set")
...
$ foobar gen-config -o ./config.go
...
$ cat ./config.o
type Config struct {
Foo string `mapstructure:"foo"`
FooBar string `mapstructure:"foo-bar"`
}
So kind of self-updating code. The tricky part is to how to start this process. This could be done simply by having a dummy struct in the beginning to make sure code compiles.
Hide all logrus specific code behind a build tag
Lets add short -l
for logging as it is very common to have it anyway
WORKS
type Foo struct {
bar string `flag:"bar,bananza,Barness"`
}
DOESN'T WORK
type Bar string
type Foo struct {
bar Bar `flag:"bar,bananza,Barness"`
}
While it is still a string, it works only in the first case.
We can keep default one, we can change it but currently we can't clear it. Lets update code to support this option for --env-prefix
flag.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.