本文整理汇总了TypeScript中commander.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了on函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: CliCreateEmbedToken
export default function CliCreateEmbedToken() {
let pkg = require('../package.json');
function list(val) {
return val.split(',');
}
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-w, --workspace <workspaceId>', 'The Power BI workspace id')
.option('-r, --report <reportId>', 'The Power BI report id')
.option('-d, --dataset <datasetId>', 'The Power BI dataset id')
.option('-s, --scopes [scopes]', 'The permission scopes allowed')
.option('-u, --username [username]', 'The RLS username')
.option('--roles [roles]', 'The RLS roles', list)
.option('-e, --expiration <expiration>', 'The token expiration date');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-embed-token -c <collection>, -w <workspace> -r <reportId> -k <accessKey> -u [username] --roles [roles1,roles2,...]');
console.log(' $ powerbi create-embed-token -c <collection>, -w <workspace> -r <reportId> -k <accessKey> -s [scopes]');
console.log(' $ powerbi create-embed-token -c <collection>, -w <workspace> -d <datasetId> -k <accessKey> -s [scopes]');
console.log(' Create report in embedded view needs the following scopes: "Dataset.Read Workspace.Report.Create"');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let token: powerbi.PowerBIToken = null;
if (!settings.accessKey) {
return cli.error('Access key param is required');
}
if (!(settings.collection && settings.workspace)) {
return cli.error('collection and workspace params are required');
}
if (!(settings.report || settings.dataset)) {
return cli.error('Either reportId or datasetId must be set');
}
let expiration = settings.expiration ? new Date(settings.expiration) : void 0;
token = powerbi.PowerBIToken.createReportEmbedToken(settings.collection, settings.workspace, settings.report, settings.dataset, settings.scopes, settings.username, settings.roles, expiration);
let jwt = token.generate(settings.accessKey);
cli.success('Embed Token: ', jwt);
} catch (err) {
cli.error(err);
}
}
}
示例2: CliCloneReprot
export default function CliCloneReprot() {
let pkg = require('../package.json');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-w, --workspace <workspace>', 'The Power BI workspace')
.option('-r, --report <reportKey>', 'The report to clone')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-n, --newName <newName>', 'The new report name')
.option('-t, --tworkspace [targetWorkspace]', 'New target workspace to save report in. default is original report workspace.')
.option('-d, --tdataset [targetDatasetKey]', 'New target dataset to rebind report with. default is original report dataset.')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Description:');
console.log('');
console.log(' Clones a report and gives name to new report.');
console.log(' Assign target workspace to save the new report in a specific workspace.');
console.log(' Assign target dataset to rebind the new report with a specific dataset.');
console.log(' When moving between workspaces, the dataset has to reside within the targeted workspace.');
console.log('');
console.log(' Examples:');
console.log('');
console.log(' $ powerbi clone-report -c <collection> -w <workspace> -k <accessKey> -r <report> -n <newName>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey && settings.workspace && settings.report && settings.newName)) {
program.help();
}
try {
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
let params: powerbi.CloneReportRequest = {
name: settings.newName,
targetWorkspaceId: settings.tworkspace,
targetModelId: settings.tdataset
};
client.reports.cloneReport(settings.collection, settings.workspace, settings.report, params, (err, result) => {
if (err) {
return cli.error(err);
}
cli.print('New report ID: %s', result.id);
cli.print('Name: %s', result.name);
cli.print('EmbedUrl: %s', result.embedUrl);
cli.success('Clone report has been completed successfully');
});
} catch (err) {
cli.error(err);
}
}
示例3: CliGetReports
export default function CliGetReports() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-w, --workspace <workspace>', 'The Power BI workspace')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi get-reports -c <collection> -w <workspace> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey && settings.workspace)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.reports.getReports(settings.collection, settings.workspace, (err, result) => {
if (err) {
return cli.error(err);
}
let reports = result.value;
if (reports.length === 0) {
return cli.warn('No reports found within workspace: %s', settings.workspace);
}
cli.print('=========================================');
cli.print('Gettings reports for Collection: %s', settings.workspace);
cli.print('=========================================');
reports.forEach(report => {
cli.print('ID: %s | Name: %s', report.id, report.name);
});
});
} catch (err) {
cli.error(err);
}
}
}
示例4: CliGetWorkspaces
export default function CliGetWorkspaces() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi get-workspaces -c <collection> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.workspaces.getWorkspacesByCollectionName(settings.collection, (err, result) => {
if (err) {
return cli.error(err);
}
let workspaces = result.value;
if (workspaces.length == 0) {
return cli.warn('No workspaces found within collection: %s', settings.collection);
}
cli.print("================================================");
cli.print('Gettings workspaces for Collection: %s', settings.collection);
cli.print("================================================");
result.value.forEach(workspace => {
cli.print(workspace.workspaceId);
});
});
} catch (_error) {
err = _error;
cli.error(err);
}
}
}
示例5: CliRebindReport
export default function CliRebindReport() {
let pkg = require('../package.json');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-w, --workspace <workspace>', 'The Power BI workspace Id')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-r, --report <reportId>', 'The Power BI report id')
.option('-d, --dataset <datasetId>', 'The Power BI dataset id')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Description:');
console.log('');
console.log(' Rebinds a report with another dataset. Old dataset and new dataset should have the same schema.');
console.log('');
console.log(' Examples:');
console.log('');
console.log(' $ powerbi rebind-report -c <collection> -w <workspace> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.workspace && settings.accessKey && settings.report && settings.dataset)) {
program.help();
return;
}
try {
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
let params: powerbi.RebindReportRequest = { datasetId: settings.dataset };
client.reports.rebindReport(settings.collection, settings.workspace, settings.report, params, (err, result) => {
if (err) {
return cli.error(err);
}
cli.success('Rebind report has been completed successfully');
});
} catch (err) {
cli.error(err);
}
}
示例6: CliDeleteDataset
export default function CliDeleteDataset() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-w, --workspace <workspace>', 'The Power BI workspace')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-d, --dataset <dataset>', 'The dataset id')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi delete-dataset -c <collection> -w <workspace> -d <dataset> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey && settings.workspace)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createDevToken(settings.collection, settings.workspace);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.datasets.deleteDatasetById(settings.collection, settings.workspace, settings.dataset, (err, result) => {
if (err) {
return cli.error(err);
}
cli.success('Dataset %s deleted successfully', settings.dataset);
});
} catch (err) {
cli.error(err);
}
}
}
示例7: CliCreateWorkspace
export default function CliCreateWorkspace() {
let pkg = require('../package.json');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-b --baseUri [baseUri]', 'The base uri to connect to')
.option('-n --newName [newName]', 'The name of the workspace');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-workspace -c <collection> -k <accessKey> -n <newName>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let credentials = new msrest.TokenCredentials(settings.accessKey, 'AppKey');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
let workspaceRequest : powerbi.CreateWorkspaceRequest = {
name: settings.newName,
};
let options = { workspaceRequest }
client.workspaces.postWorkspace(settings.collection, options, (err, result) => {
if (err) {
return cli.error(err);
}
cli.print('Workspace created: %s', result.workspaceId);
});
} catch (err) {
cli.error(err);
}
}
}
示例8: CliCreateWorkspace
export default function CliCreateWorkspace() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
program.version(pkg.version)
.option('-c, --collection <collection>', 'The Power BI workspace collection')
.option('-k, --accessKey <accessKey>', 'The Power BI workspace collection access key')
.option('-b --baseUri [baseUri]', 'The base uri to connect to');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi create-workspace -c <collection> -k <accessKey>');
});
program.parse(process.argv);
let settings = config.merge(program);
if (!(settings.collection && settings.accessKey)) {
program.help();
} else {
try {
let token = powerbi.PowerBIToken.createProvisionToken(settings.collection);
let credentials = new msrest.TokenCredentials(token.generate(settings.accessKey), 'AppToken');
let client = new powerbi.PowerBIClient(credentials, settings.baseUri, null);
client.workspaces.postWorkspace(settings.collection, (err, result) => {
if (err) {
return cli.error(err);
}
cli.print('Workspace created: %s', result.workspaceId);
});
} catch (err) {
cli.error(err);
}
}
}
示例9: CliConfig
export default function CliConfig() {
let err;
let program = require('commander');
let colors = require('colors');
let pkg = require('../package.json');
let util = require('util');
program.version(pkg.version)
.option('-c, --collection [collection]', 'The Power BI workspace collection')
.option('-w, --workspace [workspaceId]', 'The Power BI workspace')
.option('-k, --accessKey [accessKey]', 'The Power BI workspace collection access key')
.option('-b, --baseUri [baseUri]', 'The base uri to connect to')
.option('-clear, --clear [clear]', 'Clears the settings');
program.on('--help', function () {
console.log(' Examples:');
console.log('');
console.log(' $ powerbi config -c <collection> -k <accessKey> -w <workspace>');
});
program.parse(process.argv);
try {
let properties = ['collection', 'workspace', 'accessKey', 'baseUri'];
let currentConfig = config.get();
properties.forEach(key => {
if (program[key]) {
currentConfig[key] = program[key];
}
});
config.set(currentConfig);
for (var key in currentConfig) {
cli.print('%s: %s', key, currentConfig[key]);
}
} catch (err) {
cli.error(err);
}
}
示例10:
console.log(' float: %j', program.float);
console.log(' optional: %j', program.optional);
program.range = program.range || [];
console.log(' range: %j..%j', program.range[0], program.range[1]);
console.log(' list: %j', program.list);
console.log(' collect: %j', program.collect);
console.log(' verbosity: %j', program.verbose);
console.log(' args: %j', program.args);
program
.version('0.0.1')
.option('-f, --foo', 'enable some foo')
.option('-b, --bar', 'enable some bar')
.option('-B, --baz', 'enable some baz');
// must be before .parse() since
// node's emit() is immediate
program.on('--help', () => {
console.log(' Examples:');
console.log('');
console.log(' $ custom-help --help');
console.log(' $ custom-help -h');
console.log('');
});
program.parse(process.argv);
console.log('stuff');