1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
# Config
Allows to persist options
```sh
wb config <key> [value]
```
## Summary
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [commands](#commands)
- [get](#get)
- [set](#set)
- [path](#path)
- [reset](#reset)
- [options](#options)
- [credentials](#credentials)
- [bot](#bot)
- [maxlag](#maxlag)
- [lang](#lang)
- [json](#json)
- [clipboard](#clipboard)
- [verbose](#verbose)
- [custom Wikibase instance](#custom-wikibase-instance)
- [custom SPARQL endpoint](#custom-sparql-endpoint)
- [environment variables](#environment-variables)
- [Backup config](#backup-config)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## commands
### get
```sh
# Output the current config and the help menu
wb config
# Output the config value for the key 'clipboard'
wb config clipboard
# For wb config credentials
```
### set
```sh
wb config clipboard true
```
### path
get config file path
```sh
wb config path
```
### reset
Reset a single parameter to come back to its default value
```sh
wb config instance reset
```
or clear the whole config
```sh
wb config reset
```
## options
### credentials
Required for [write operations](https://github.com/maxlath/wikibase-cli/blob/main/docs/write_operations.md)
```sh
# Output the current credentials for a given instance
# If no credentials are set for this instance, start a prompt session to add credentials,
# either OAuth tokens (recommended) or a username and password
wb config credentials https://www.wikidata.org
# Reset those credentials
wb config credentials https://www.wikidata.org reset
# Get the prompt again
wb config credentials https://www.wikidata.org
# Test your credentials validity
wb config credentials https://www.wikidata.org test
```
:warning: Be aware that your credentials will be persisted on your file system as clear text (until we find a better way to do that). It is thus recommended to use OAuth* tokens when possible, with minimal authorizations.
(\*) Yes, just the sight of word OAuth might give you chills, but setting up an [owner-only consumers](https://www.mediawiki.org/wiki/OAuth/Owner-only_consumers) is actually super fast (no need for validation) and rather simple: just follow the `wb config credentials https://my.wikibase.instance` prompt instructions.
:warning: Individual calls to `wb` do re-login every time, as cookies are not stored between sessions. An [excessive number of logins to Wikibase should be avoided](https://phabricator.wikimedia.org/T256533): if you need to perform a lot of edits, you are strongly advised to use the [batch mode](https://github.com/maxlath/wikibase-cli/blob/main/docs/write_operations.md#batch-mode).
### bot
Set a bot flag on requests made by a bot account is [required](https://www.wikidata.org/wiki/Wikidata:Bots#All_bots) and can be done by setting the `config.bot` value:
```sh
# Default: false
wb config bot true
```
### maxlag
Set the [`maxlag`](https://www.mediawiki.org/wiki/Manual:Maxlag_parameter) value
```sh
# Default: 5
wb config maxlag 10
```
### lang
Set the preferred language (same as `-l, --lang`)
```sh
# Default: process.env.LANG.slice(0, 2)
wb config lang nl
```
### json
Format the output of commands as JSON, when possible (same as `-j, --json`)
```sh
# Default: false
wb config json true
```
### clipboard
Copy command results to the clipboard, when this option is available (same as `-c, --clipboard`)
```sh
# Default: false
wb config clipboard true
```
### verbose
Set commands to print verbose output (same as `-v, --verbose`)
```sh
# Default: false
wb config verbose true
```
### custom Wikibase instance
You may want to use those commands against a different [Wikibase](http://wikiba.se) than `wikidata.org` (same as `-i, --instance`)
```sh
# Default: https://wikidata.org/w/api.php
wb config instance https://mywikibase.instance/w/api.php
```
You're all set to make requests against your custom instance:
```sh
wb label Q1
wb claims Q1
wb data Q1
wb open Q1
```
### custom SPARQL endpoint
You can also set a custom SPARQL endpoint (same as `-e, --sparql-endpoint`)
```sh
# Default: https://query.wikidata.org/sparql
wb config sparql-endpoint https://example.com/sparql
```
You're all set to make requests against your custom instance:
```sh
wb query --property P2002 --object timberners_lee
```
## environment variables
Alternatively to using `wb config`, you can set environment variables. Priority is given to the command line options, then environment variables, then config values.
```sh
export WB_INSTANCE=https://wikibase-registry.wmflabs.org/w/api.php ; wb label Q2
# => Wikibase
export WB_INSTANCE=https://www.wikidata.org/w/api.php ; wb label Q2
# => Earth
```
Available variables:
* `WB_BOT`
* `WB_CLIPBOARD`
* `WB_INSTANCE`
* `WB_JSON`
* `WB_LANG`
* `WB_MAXLAG`
* `WB_SPARQL_ENDPOINT`
* `WB_VERBOSE`
Those variables can be useful if you work with several instances, you could set aliases in your shell environment to target specifically one instance or the other:
```sh
wdt(){
export WB_INSTANCE=https://test.wikidata.org
wb "$@"
}
wdt search foo
```
## Backup config
Backup:
```sh
wb config --json > config.json
# or
cp $(wb config path) config.json
```
Restore:
```sh
cp config.json $(wb config path)
```
|