draft-redmine_users_from_csv/main.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-01-15 22:55:53 +01:00
import { Redmine } from 'bluemine'
import * as CSV from 'std:csv'
import { CsvEntry } from './type.ts'
2024-01-15 22:55:53 +01:00
import { createUsers } from './src/create_users.ts'
import { appendToGroup } from './src/append_to_group.ts'
import { Command } from 'cliffy'
2024-01-15 22:55:53 +01:00
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('-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 },
2024-01-15 22:55:53 +01:00
)
.arguments('<csv:file>')
.action(async ({ group, endpoint, apiKey }, domain) => {
const redmine = new Redmine({ endpoint, apiKey })
2024-01-15 22:55:53 +01:00
const file = await Deno.readTextFile(domain)
2024-01-15 22:55:53 +01:00
const csv = CSV.parse(file.replaceAll(';', ','), {
skipFirstRow: true,
}) as CsvEntry[]
2024-01-15 22:55:53 +01:00
createUsers(redmine, csv)
if (group) {
appendToGroup(redmine, csv, prompt('Enter a group name ?: ') ?? '')
}
})
.parse()