Skip to content

Commit

Permalink
add config flag (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir authored Jul 5, 2023
1 parent 42769b4 commit 5b21d47
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ type Options struct {
// ParseOptions parses the command line options for application
func ParseOptions() *Options {
options := &Options{}
var cfgFile string

flagSet := goflags.NewFlagSet()
flagSet.SetDescription(`httpx is a fast and multi-purpose HTTP toolkit that allows running multiple probes using the retryablehttp library.`)
Expand Down Expand Up @@ -383,6 +384,7 @@ func ParseOptions() *Options {
)

flagSet.CreateGroup("configs", "Configurations",
flagSet.StringVar(&cfgFile, "config", "", "path to the httpx configuration file (default $HOME/.config/httpx/config.yaml)"),
flagSet.StringSliceVarP(&options.Resolvers, "resolvers", "r", nil, "list of custom resolver (file or comma separated)", goflags.NormalizedStringSliceOptions),
flagSet.Var(&options.Allow, "allow", "allowed list of IP/CIDR's to process (file or comma separated)"),
flagSet.Var(&options.Deny, "deny", "denied list of IP/CIDR's to process (file or comma separated)"),
Expand Down Expand Up @@ -435,6 +437,16 @@ func ParseOptions() *Options {

_ = flagSet.Parse()

if cfgFile != "" {
if !fileutil.FileExists(cfgFile) {
gologger.Fatal().Msgf("given config file '%s' does not exist", cfgFile)
}
// merge config file with flags
if err := flagSet.MergeConfigFile(cfgFile); err != nil {
gologger.Fatal().Msgf("Could not read config: %s\n", err)
}
}

if options.HealthCheck {
gologger.Print().Msgf("%s\n", DoHealthCheck(options, flagSet))
os.Exit(0)
Expand Down

0 comments on commit 5b21d47

Please sign in to comment.