@dittowords/cli 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/lib/config.js +10 -0
- package/lib/init/token.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,17 @@ After selecting a project, a configuration file will automatically be created at
|
|
|
50
50
|
|
|
51
51
|
Once you've successfully authenticated and a config file has been created, you’re ready to start fetching copy! You can set up the CLI in multiple directories by running `ditto-cli` and choosing an initial project to sync from.
|
|
52
52
|
|
|
53
|
+
## API Keys
|
|
54
|
+
|
|
55
|
+
The CLI will not prompt for an API key if a value is provided in the environment variable `DITTO_API_KEY`.
|
|
56
|
+
|
|
57
|
+
If the `DITTO_API_KEY` environment variable is not set, then the CLI will attempt to parse a token from a file at the
|
|
58
|
+
path `~/.config/ditto`. If this file does not exist or does not contain a valid API key, then the CLI will prompt
|
|
59
|
+
for one.
|
|
60
|
+
|
|
61
|
+
We don't recommend editing the file manually; if you need to remove a saved API key and put another one in its place,
|
|
62
|
+
it's better to fully delete the file and then re-run the CLI so that a new key is prompted for.
|
|
63
|
+
|
|
53
64
|
## Commands
|
|
54
65
|
|
|
55
66
|
### `pull`
|
package/lib/config.js
CHANGED
|
@@ -57,7 +57,16 @@ function saveToken(file, host, token) {
|
|
|
57
57
|
writeData(file, data);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
function getTokenFromEnv() {
|
|
61
|
+
return process.env.DITTO_API_KEY;
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
function getToken(file, host) {
|
|
65
|
+
const tokenFromEnv = getTokenFromEnv();
|
|
66
|
+
if (tokenFromEnv) {
|
|
67
|
+
return tokenFromEnv;
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
const data = readData(file);
|
|
62
71
|
const hostEntry = data[justTheHost(host)];
|
|
63
72
|
if (!hostEntry) return undefined;
|
|
@@ -154,6 +163,7 @@ module.exports = {
|
|
|
154
163
|
saveToken,
|
|
155
164
|
deleteToken,
|
|
156
165
|
getToken,
|
|
166
|
+
getTokenFromEnv,
|
|
157
167
|
save,
|
|
158
168
|
parseSourceInformation,
|
|
159
169
|
};
|
package/lib/init/token.js
CHANGED
|
@@ -10,6 +10,10 @@ const output = require("../output");
|
|
|
10
10
|
const config = require("../config");
|
|
11
11
|
|
|
12
12
|
function needsToken(configFile, host = consts.API_HOST) {
|
|
13
|
+
if (config.getTokenFromEnv()) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
const file = configFile || consts.CONFIG_FILE;
|
|
14
18
|
if (!fs.existsSync(file)) return true;
|
|
15
19
|
const configData = config.readData(file);
|