Skip to content

Commit 3a3c1b9

Browse files
committed
Fixed #74: Make .gau.toml file location configurable
1 parent 4b24510 commit 3a3c1b9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $ gau -h
2828
| Flag | Description | Example |
2929
|------|-------------|---------|
3030
|`--blacklist`| list of extensions to skip | gau --blacklist ttf,woff,svg,png|
31+
|`--config` | Use alternate configuration file (default `$HOME/config.toml` or `%USERPROFILE%\.gau.toml`) | gau --config $HOME/.config/gau.toml|
3132
|`--fc`| list of status codes to filter | gau --fc 404,302 |
3233
|`--from`| fetch urls from date (format: YYYYMM) | gau --from 202101 |
3334
|`--ft`| list of mime-types to filter | gau --ft text/plain|
@@ -48,7 +49,9 @@ $ gau -h
4849

4950

5051
## Configuration Files
51-
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.
52+
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**.
53+
54+
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.
5255

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

runner/flags/flags.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func New() *Options {
9999
v := viper.New()
100100

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

136137
func (o *Options) ReadInConfig() (*Config, error) {
137-
home, err := os.UserHomeDir()
138-
if err != nil {
139-
return o.DefaultConfig(), err
138+
confFile := o.viper.GetString("config")
139+
140+
if confFile == "" {
141+
home, err := os.UserHomeDir()
142+
if err != nil {
143+
return o.DefaultConfig(), err
144+
}
145+
146+
confFile = filepath.Join(home, ".gau.toml")
140147
}
141148

142-
confFile := filepath.Join(home, ".gau.toml")
143149
return o.ReadConfigFile(confFile)
144150
}
145151

0 commit comments

Comments
 (0)