Skip to content

Commit

Permalink
Fixed #74: Make .gau.toml file location configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou committed Oct 25, 2024
1 parent 4b24510 commit 3a3c1b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ $ gau -h
| Flag | Description | Example |
|------|-------------|---------|
|`--blacklist`| list of extensions to skip | gau --blacklist ttf,woff,svg,png|
|`--config` | Use alternate configuration file (default `$HOME/config.toml` or `%USERPROFILE%\.gau.toml`) | gau --config $HOME/.config/gau.toml|
|`--fc`| list of status codes to filter | gau --fc 404,302 |
|`--from`| fetch urls from date (format: YYYYMM) | gau --from 202101 |
|`--ft`| list of mime-types to filter | gau --ft text/plain|
Expand All @@ -48,7 +49,9 @@ $ gau -h


## Configuration Files
gau automatically looks for a configuration file at `$HOME/.gau.toml` or`%USERPROFILE%\.gau.toml`. You can specify options and they will be used for every subsequent run of gau. Any options provided via command line flags will override options set in the configuration file.
gau automatically looks for a configuration file at `$HOME/.gau.toml` or`%USERPROFILE%\.gau.toml`. You can point to a different configuration file using the `--config` flag. **If the configuration file is not found, gau will still run with a default configuration, but will output a message to stderr**.

You can specify options and they will be used for every subsequent run of gau. Any options provided via command line flags will override options set in the configuration file.

An example configuration file can be found [here](https://github.com/lc/gau/blob/master/.gau.toml)

Expand Down
14 changes: 10 additions & 4 deletions runner/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func New() *Options {
v := viper.New()

pflag.String("o", "", "filename to write results to")
pflag.String("config", "", "location of config file (default $HOME/.gau.toml or %USERPROFILE%\\.gau.toml)")
pflag.Uint("threads", 1, "number of workers to spawn")
pflag.Uint("timeout", 45, "timeout (in seconds) for HTTP client")
pflag.Uint("retries", 0, "retries for HTTP client")
Expand Down Expand Up @@ -134,12 +135,17 @@ func Args() []string {
}

func (o *Options) ReadInConfig() (*Config, error) {
home, err := os.UserHomeDir()
if err != nil {
return o.DefaultConfig(), err
confFile := o.viper.GetString("config")

if confFile == "" {
home, err := os.UserHomeDir()
if err != nil {
return o.DefaultConfig(), err
}

confFile = filepath.Join(home, ".gau.toml")
}

confFile := filepath.Join(home, ".gau.toml")
return o.ReadConfigFile(confFile)
}

Expand Down

0 comments on commit 3a3c1b9

Please sign in to comment.