i18nexus-cli
Version:
Command line interface (CLI) for accessing the i18nexus API
32 lines (24 loc) • 735 B
JavaScript
const colors = require('colors');
const handleError = require('../handleError');
const handleFetch = require('../handleFetch');
const baseUrl = require('../baseUrl');
const addNamespace = async opt => {
let url = `${baseUrl}/project_resources/namespaces.json`;
url += `?api_key=${opt.apiKey}`;
const response = await handleFetch(url, {
method: 'POST',
body: JSON.stringify({
title: opt.title
}),
headers: {
Authorization: `Bearer ${opt.pat}`,
'Content-Type': 'application/json'
}
});
if (response.status !== 200) {
return handleError(response);
}
await response.json();
console.log(colors.green(`New namespace added: "${opt.title}"`));
};
module.exports = addNamespace;