mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
add CLI support
This commit is contained in:
parent
564db6961a
commit
cef6fee5ac
3 changed files with 58 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
|
||||
### UNRELEASED
|
||||
- add CLI support to manage accounts (list / modify / add accounts)
|
||||
### 1.4.3 - 10 mar '22
|
||||
- fix [#140](https://framagit.org/les/gancio/-/issues/140) - Invalid date
|
||||
- fix [#141](https://framagit.org/les/gancio/-/issues/141) - Cannot change logo
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env node
|
||||
const pkg = require('../package.json')
|
||||
const path = require('path')
|
||||
const accountsCLI = require('./cli/accounts')
|
||||
|
||||
process.env.cwd = process.env.GANCIO_DATA || path.resolve('./')
|
||||
|
||||
|
@ -28,6 +29,7 @@ require('yargs')
|
|||
process.env.config_path = absolute_config_path
|
||||
return absolute_config_path
|
||||
})
|
||||
.command(['accounts'], 'Manage accounts', accountsCLI)
|
||||
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
|
|
54
server/cli/accounts.js
Normal file
54
server/cli/accounts.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
function _initializeDB () {
|
||||
const config = require('../config')
|
||||
config.load()
|
||||
config.log_level = 'error'
|
||||
const db = require('../api/models/index')
|
||||
return db.initialize()
|
||||
}
|
||||
|
||||
async function modify (args) {
|
||||
await _initializeDB()
|
||||
const helpers = require('../helpers')
|
||||
const User = require('../api/models/user')
|
||||
const user = await User.findOne({ where: { email: args.account } })
|
||||
console.log()
|
||||
if (!user) {
|
||||
console.error(`User ${args.account} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
if (args['reset-password']) {
|
||||
const password = helpers.randomString()
|
||||
user.password = password
|
||||
await user.save()
|
||||
console.log(`New password for user ${user.email} is '${password}'`)
|
||||
}
|
||||
}
|
||||
|
||||
async function add (args) {
|
||||
}
|
||||
|
||||
async function list () {
|
||||
await _initializeDB()
|
||||
const User = require('../api/models/user')
|
||||
const users = await User.findAll()
|
||||
console.log()
|
||||
users.forEach(u => console.log(`${u.id}\tadmin: ${u.is_admin}\tenabled: ${u.is_active}\temail: ${u.email} - ${u.password}`))
|
||||
console.log()
|
||||
}
|
||||
|
||||
const accountsCLI = yargs => {
|
||||
return yargs
|
||||
.command('list', 'List all accounts', list)
|
||||
.command('modify', 'Modify', {
|
||||
account: {
|
||||
describe: 'Account to modify'
|
||||
},
|
||||
'reset-password': {
|
||||
describe: 'Resets the password of the given accoun '
|
||||
}
|
||||
}, modify)
|
||||
.command('add', 'Add an account', {}, add)
|
||||
}
|
||||
|
||||
module.exports = accountsCLI
|
Loading…
Reference in a new issue