Skip to content

Commit 4f523c6

Browse files
committed
docs(cli): add configuration section for docs/cli.md
- below contents added. - global option for commands - paths where the fedify command looks for the configuration files (on Linux/macOS/Windows) - available configuration fields - who wins when there are different settings are provided through CLI options and configuration files
1 parent 3f7c485 commit 4f523c6

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

docs/cli.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,101 @@ the appropriate executable for your platform and put it in your `PATH`.
102102
[releases]: https://github.com/fedify-dev/fedify/releases
103103

104104

105+
Configuration
106+
-------------
107+
108+
The `fedify` command can be configured via configuration files. This allows
109+
you to set default options for various commands without having to specify them
110+
on the command line every time.
111+
112+
To disable loading configuration files, you can use the `--no-config` global
113+
option.
114+
115+
### Configuration Files
116+
117+
`fedify` looks for configuration files with the following names:
118+
119+
- `.fedifyrc`
120+
- `fedify.config.json`
121+
122+
The files are expected to be in JSON format.
123+
124+
### Configuration File Locations
125+
126+
The `fedify` command searches for configuration files in the following
127+
locations, in order:
128+
129+
1. **Current Directory**: The directory from which you run the `fedify`
130+
command.
131+
- `./.fedifyrc`
132+
- `./fedify.config.json`
133+
134+
2. **System-Specific Configuration Directory**:
135+
- **Linux and macOS**: Based on the [XDG Base Directory Specification],
136+
`fedify` looks in `$XDG_CONFIG_HOME/fedify/`. If `$XDG_CONFIG_HOME`
137+
is not set, it defaults to `~/.config/fedify/`.
138+
- `$XDG_CONFIG_HOME/fedify/.fedifyrc`
139+
- `$XDG_CONFIG_HOME/fedify/fedify.config.json`
140+
- **Windows**: `fedify` looks in the directory obtained from the `APPDATA`
141+
environment variable. If `APPDATA` is not set, it falls back to
142+
`%USERPROFILE%\AppData\Roaming`. The configuration directory will be
143+
`APPDATA\fedify\`.
144+
- `%APPDATA%\fedify\.fedifyrc`
145+
- `%APPDATA%\fedify\fedify.config.json`
146+
147+
`fedify` will use the first configuration file it finds and stop searching.
148+
149+
[XDG Base Directory Specification]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
150+
151+
### Precedence
152+
153+
The settings are applied with the following precedence, from highest to lowest:
154+
155+
1. Command-line options (e.g., `--cache-dir`, `--verbose`).
156+
2. Configuration file in the current working directory (`.fedifyrc` takes
157+
precedence over `fedify.config.json`).
158+
3. Configuration file in the system-specific configuration directory
159+
(`.fedifyrc` takes precedence over `fedify.config.json`).
160+
161+
For example, if `cacheDir` is specified in a configuration file, but you also
162+
provide the `--cache-dir` option on the command line, the value from the
163+
command line option will be used.
164+
165+
### Available Fields
166+
167+
The following fields are available in the configuration file:
168+
169+
~~~~ json
170+
{
171+
"cacheDir": "/path/to/cache",
172+
"verbose": true,
173+
"http": {
174+
"timeout": 30000,
175+
"userAgent": "MyFedifyClient/1.0",
176+
"followRedirects": true
177+
},
178+
"format": {
179+
"default": "json"
180+
}
181+
}
182+
~~~~
183+
184+
- `cacheDir` (string): Path to the cache directory. Corresponds to the global
185+
`--cache-dir` option.
186+
- `verbose` (boolean): Enable verbose output. Corresponds to the global
187+
`-v`/`--verbose` option.
188+
- `http` (object): HTTP-related settings.
189+
- `timeout` (number): Timeout for HTTP requests in milliseconds.
190+
- `userAgent` (string): The `User-Agent` header for HTTP requests.
191+
Corresponds to the `--user-agent` option in commands like `lookup` and
192+
`nodeinfo`.
193+
- `followRedirects` (boolean): Whether to automatically follow HTTP
194+
redirects (e.g., 301, 302, 307, 308 status codes) when making requests.
195+
Defaults to `true`.
196+
- `format` (object): Output formatting options for commands like `lookup`.
197+
- `default` (string): Default output format. Can be `json`, `json-ld`, or
198+
`yaml`.
199+
105200
`fedify init`: Initializing a Fedify project
106201
--------------------------------------------
107202

0 commit comments

Comments
 (0)