bwplotka / flagarize Goto Github PK
View Code? Open in Web Editor NEWFlagarize your Go struct to initialize your even complex struct from flags! ๐
Home Page: https://bwplotka.dev/
License: Apache License 2.0
Flagarize your Go struct to initialize your even complex struct from flags! ๐
Home Page: https://bwplotka.dev/
License: Apache License 2.0
I kind of like variable interpolation instead my current special string field for custom field like it is done here: https://github.com/alecthomas/kong#variable-interpolation
๐ค
I think I would be happy to have this implemented before 1.0. Help wanted (:
Requires custom structTag.Get implementation as mentioned here: https://stackoverflow.com/questions/51984366/how-to-split-long-struct-tags-in-golang
The Go totally works with newlines in tags:
var err error
cfg := struct {
ConfigFile string `flagarize:"name=config.file|help=Prometheus configuration file path.|default=prometheus.yml"`
ExternalURL string `flagarize:"name=web.external-url|help=The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). \
Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically.|placeholder=<URL>"`
StoragePath string `flagarize:"name=storage.tsdb.path|help=Base path for metrics storage.|default=data/"`
RemoteFlushDeadline model.Duration `flagarize:"name=storage.remote.flush-deadline|help=How long to wait flushing sample on shutdown or config reload.|default=1m|placeholder=<duration>"`
RulesOutageTolerance model.Duration `flagarize:"name=rules.alert.for-outage-tolerance|help=Max time to tolerate prometheus outage for restoring \"for\" state of alert.|default=1h"`
RulesForGracePeriod model.Duration `flagarize:"name=rules.alert.for-grace-period|help=Minimum duration between alert and restored \"for\" state. This is maintained only for alerts with configured \"for\" time greater than grace period.|default=10m"`
RulesResendDelay model.Duration `flagarize:"name=rules.alert.resend-delay|help=Minimum amount of time to wait before resending an alert to Alertmanager.|default=1m"`
LookbackDelta model.Duration `flagarize:"name=query.lookback-delta|help=The maximum lookback duration for retrieving metrics during expression evaluations and federation.|default=5m"`
QueryTimeout model.Duration `flagarize:"name=query.timeout|help=Maximum time a query may take before being aborted.|default=2m"`
QueryConcurrency int `flagarize:"name=query.max-concurrency|help=Maximum number of queries executed concurrently.|default=20"`
QueryMaxSamples int `flagarize:"name=query.max-samples|help=Maximum number of samples a single query can load into memory. Note that queries will fail if \
they try to load more samples than this into memory, so this also limits the number of samples a query can return.|default=50000000"`
Web web.Options
Notifier notifier.Options
TSDB tsdbOptions
PromLog promlog.Config
}{
Notifier: notifier.Options{
Registerer: prometheus.DefaultRegisterer,
},
Web: web.Options{
Registerer: prometheus.DefaultRegisterer,
Gatherer: prometheus.DefaultGatherer,
CORSOriginFlagarizeHelp: `Regex for CORS origin. It is fully anchored. Example: 'https?://(domain1|domain2)\.com'`,
},
TSDB: tsdbOptions{
RetentionDurationFlagarizeHelp: "How long to retain samples in storage. When this flag is set it overrides \"storage.tsdb.retention\". If neither this flag nor \"storage.tsdb.retention\" nor \"storage.tsdb.retention.size\" is set, the retention time defaults to " + defaultRetentionString + ". Units Supported: y, w, d, h, m, s, ms.",
},
PromLog: promlog.Config{},
}
a := kingpin.New(filepath.Base(os.Args[0]), "The Prometheus monitoring server")
a.Version(version.Print("prometheus"))
a.HelpFlag.Short('h')
if err := flagarize.Flagarize(a, &cfg); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
if _, err := a.Parse(os.Args[1:]); err != nil {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Error parsing commandline arguments"))
a.Usage(os.Args[1:])
os.Exit(2)
}
There is really no point in that, that's why it's not allowed - would be nice to return a nice error for that thought ๐ค
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.