Skip to content

Commit 340b7b2

Browse files
committed
add ability to login via env
1 parent 3c3e78b commit 340b7b2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ All available configurations are listed in the table below.
5353
| ------------ |:--------------------- | ---------- | ------------------------------ | ------------------------------------ |
5454
| `serverUrl` | `CMD_CLI_SERVER_URL` | *`string`* | `https://my.codimd-domain.dev` | The CodiMD instance URL |
5555
| `cookiePath` | `CMD_CLI_COOKIE_PATH` | *`string`* | `~/.codimd/cookies.json` | File for storing login cookie states |
56+
| _n/a_ | `CMD_CLI_ID` | *`string`* | `me@codimd-domain.dev` | CodiMD username/email |
57+
| _n/a_ | `CMD_CLI_PASSWORD` | *`string`* | `dragon` | CodiMD password |
58+
59+
_Don't commit your login credentials!_
5660

5761
## Commands
5862

@@ -171,6 +175,8 @@ EXAMPLE
171175
Login as HMD successfully!
172176
```
173177

178+
Alternatively, you may supply an email and password via the `CMD_EMAIL` and `CMD_PASSWORD` environment variables, respectively.
179+
174180
_See code: [src/commands/login.ts](https://github.com/hackmdio/codimd-cli/blob/v1.0.3/src/commands/login.ts)_
175181

176182
### `codimd-cli logout`

src/commands/login.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Login as HMD successfully!
2525
async run() {
2626
const {flags} = this.parse(Login)
2727

28-
let id = flags.id
28+
let id = flags.id || process.env.CMD_CLI_ID
29+
let password = process.env.CMD_CLI_PASSWORD || ''
2930

3031
if (!id) {
3132
if (flags.ldap) {
@@ -52,11 +53,13 @@ Login as HMD successfully!
5253
}
5354
}
5455

55-
const {password} = await inquirer.prompt({
56+
if (!password) {
57+
password = (await inquirer.prompt({
5658
type: 'password',
5759
name: 'password',
5860
message: 'Enter your password'
59-
})
61+
})).password
62+
}
6063

6164
try {
6265
let success = false

0 commit comments

Comments
 (0)