Skip to content

Commit 8da65c4

Browse files
authored
Merge pull request #5 from boneskull/env-login
2 parents c1e7631 + 340b7b2 commit 8da65c4

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-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`

oclif.manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"1.0.3","commands":{"export":{"id":"export","description":"Export note to local file","pluginName":"@hackmd/codimd-cli","pluginType":"core","aliases":[],"examples":["$ codimd-cli export [--pdf|--md|--html] <note_id> <output_file>"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"pdf":{"name":"pdf","type":"boolean","allowNo":false},"md":{"name":"md","type":"boolean","allowNo":false},"html":{"name":"html","type":"boolean","allowNo":false}},"args":[{"name":"noteId"},{"name":"output"}]},"history":{"id":"history","description":"List history","pluginName":"@hackmd/codimd-cli","pluginType":"core","aliases":[],"examples":["$ codimd-cli history\n\nID Name\nA58r8ehYTlySO94oiC_MUA Note1\nEeNHDGocSTi70ytMMGQaaQ Note2"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"columns":{"name":"columns","type":"option","description":"only show provided columns (comma-separated)"},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)"},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo"},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","options":["csv","json","yaml"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false}},"args":[]},"import":{"id":"import","description":"Create a note from markdown file","pluginName":"@hackmd/codimd-cli","pluginType":"core","aliases":[],"examples":["$ codimd-cli import /path/to/markdown/file.md\n\nYour note is available at https://codimd.domain/note-url\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"file"}]},"login":{"id":"login","description":"Login HackMD instance from CLI","pluginName":"@hackmd/codimd-cli","pluginType":"core","aliases":[],"examples":["$ codimd-cli login\n\nEnter your email: hello@codimd.domain\nEnter your password: *******\n\nLogin as HMD successfully!\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"email":{"name":"email","type":"option","char":"u","description":"Login email"}},"args":[]},"logout":{"id":"logout","description":"Logout from CLI","pluginName":"@hackmd/codimd-cli","pluginType":"core","aliases":[],"examples":["$ codimd-cli logout\n\nYou've logged out successfully\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"whoami":{"id":"whoami","description":"Show logged in account info","pluginName":"@hackmd/codimd-cli","pluginType":"core","aliases":[],"examples":["$ codimd-cli whoami\n\nYou are logged in codimd.domain as {YOUR NAME} [user-id]\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]}}}

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)