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 ', '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 ', 'Redmine server address.', { default: 'https://projets.cohabit.fr/redmine', }) .option( '-k, --api-key ', 'Your Redmine API Key (see: https://www.redmine.org/boards/2/topics/53956/).', { required: true }, ) .arguments('') .action(async ({ group, endpoint, apiKey, onlyAdd }, domain) => { const redmine = new Redmine({ endpoint, apiKey }) const file = await Deno.readTextFile(domain) const csv = CSV.parse(file.replaceAll(';', ','), { skipFirstRow: true, }) as CsvEntry[] if (!onlyAdd) createUsers(redmine, csv) if (group) { appendToGroup(redmine, csv, prompt('Enter a group name ?: ') ?? '') } }) .parse()