Skip to content

Instantly share code, notes, and snippets.

@ikr4-m
Created January 22, 2026 17:04
Show Gist options
  • Select an option

  • Save ikr4-m/9594b90e263d354d14526bae847b2d69 to your computer and use it in GitHub Desktop.

Select an option

Save ikr4-m/9594b90e263d354d14526bae847b2d69 to your computer and use it in GitHub Desktop.
Ghost CLI for Add User
// Thanks joe-blocher for the code!
// Source: https://forum.ghost.org/t/commandline-tool-to-create-user/53279
require('./current/core/server/models/role');
const UserModel = require('./current/core/server/models/user');
const {Command} = require('./current/node_modules/commander');
const program = new Command();
program.command('add')
.description('Add a new user')
.option('--name <name>', 'Name')
.option('--email <email>', 'Email')
.option('--password <password>', 'Password')
.option('--role <role>', 'Role', 'Editor')
.action(async (options) => {
const {email, name, password, role} = options;
try {
await UserModel.User.add(
{
email,
name,
password,
roles: [role],
},
{}
);
console.log('User added successfully.');
} catch (err) {
console.error('Error adding user:', err);
}
process.exit();
});
program.parse(process.argv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment