41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { Redmine } from 'bluemine'
|
|
import * as CSV from 'std:csv'
|
|
import { CsvEntry } from './type.ts'
|
|
import { createUsers } from './src/create_users.ts'
|
|
import { appendToGroup } from './src/append_to_group.ts'
|
|
import { Command } from 'cliffy'
|
|
|
|
await new Command()
|
|
.name('redmine-csv-loader')
|
|
.description('Create Redmine users from CSV and add users to a group.')
|
|
.version('0.1.0')
|
|
.option('-g, --group <group:string>', 'Name of the group to add users in.')
|
|
.option(
|
|
'-a, --only-add [only-add:boolean]',
|
|
"Don't create users, only add them to a group",
|
|
)
|
|
.option('-d, --endpoint <endpoint:string>', 'Redmine server address.', {
|
|
default: 'https://projets.cohabit.fr/redmine',
|
|
})
|
|
.option(
|
|
'-k, --api-key <api-key:string>',
|
|
'Your Redmine API Key (see: https://www.redmine.org/boards/2/topics/53956/).',
|
|
{ required: true },
|
|
)
|
|
.arguments('<csv:file>')
|
|
.action(async ({ group, endpoint, apiKey, onlyAdd }, filePath) => {
|
|
const redmine = new Redmine({ endpoint, apiKey })
|
|
|
|
const file = await Deno.readTextFile(filePath)
|
|
|
|
const csv = CSV.parse(file.replaceAll(';', ','), {
|
|
skipFirstRow: true,
|
|
}) as CsvEntry[]
|
|
|
|
if (!onlyAdd) createUsers(redmine, csv)
|
|
if (group) {
|
|
appendToGroup(redmine, csv, group)
|
|
}
|
|
})
|
|
.parse()
|