Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Added start of cli project
Browse files Browse the repository at this point in the history
  • Loading branch information
Wallace Breza committed Apr 20, 2016
1 parent 255d88c commit 1d26221
Show file tree
Hide file tree
Showing 26 changed files with 755 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules/
typings/
**/*.js
1 change: 1 addition & 0 deletions .powerbirc
@@ -0,0 +1 @@
{"collection":"SupportDemo","workspace":"250fd527-173f-4385-9780-67e54bd3ae3a","accessKey":"Y7RBnOHgcpQTmxsjqH2CYhzZwK2Yp96p3iLWcYU3wKji7Mb0qudBFU5NAvlrUbhXuXNSbZUkWPWGkfAimiuXzw=="}
47 changes: 47 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,47 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}\\bin\\cli-get-datasets",
"stopOnEntry": false,
"args": [
"-c",
"SupportDemo",
"-k",
"Y7RBnOHgcpQTmxsjqH2CYhzZwK2Yp96p3iLWcYU3wKji7Mb0qudBFU5NAvlrUbhXuXNSbZUkWPWGkfAimiuXzw==",
"-w",
"a842fb45-514d-436a-b0e9-5529720d4868"
],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"https_proxy": "http://127.0.0.1:8888",
"http_proxy": "http:127.0.0.1:8888",
"NODE_TLS_REJECT_UNAUTHORIZED": "0",
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}
181 changes: 181 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,181 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
// A task runner that calls the Typescript compiler (tsc) and
// Compiles a HelloWorld.ts program
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the HelloWorld program to compile.
"args": [
"index.ts"
],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
// A task runner that calls the Typescript compiler (tsc) and
// compiles based on a tsconfig.json file that is present in
// the root of the folder open in VSCode
/*
{
"version": "0.1.0",

// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",

// The command is a shell script
"isShellCommand": true,

// Show the output window only if unrecognized errors occur.
"showOutput": "silent",

// Tell the tsc compiler to use the tsconfig.json from the open folder.
"args": ["-p", "."],

// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
*/
// A task runner configuration for gulp. Gulp provides a less task
// which compiles less to css.
/*
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"tasks": [
{
"taskName": "less",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the standard less compilation problem matcher.
"problemMatcher": "$lessCompile"
}
]
}
*/
// Uncomment the following section to use jake to build a workspace
// cloned from https://github.com/Microsoft/TypeScript.git
/*
{
"version": "0.1.0",
// Task runner is jake
"command": "jake",
// Need to be executed in shell / cmd
"isShellCommand": true,
"showOutput": "silent",
"tasks": [
{
// TS build command is local.
"taskName": "local",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the redefined Typescript output problem matcher.
"problemMatcher": [
"$tsc"
]
}
]
}
*/
// Uncomment the section below to use msbuild and generate problems
// for csc, cpp, tsc and vb. The configuration assumes that msbuild
// is available on the path and a solution file exists in the
// workspace folder root.
/*
{
"version": "0.1.0",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"taskSelector": "/t:",
"showOutput": "silent",
"tasks": [
{
"taskName": "build",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the standard MS compiler pattern to detect errors, warnings
// and infos in the output.
"problemMatcher": "$msCompile"
}
]
}
*/
// Uncomment the following section to use msbuild which compiles Typescript
// and less files.
/*
{
"version": "0.1.0",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"taskSelector": "/t:",
"showOutput": "silent",
"tasks": [
{
"taskName": "build",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the standard MS compiler pattern to detect errors, warnings
// and infos in the output.
"problemMatcher": [
"$msCompile",
"$lessCompile"
]
}
]
}
*/
// A task runner example that defines a problemMatcher inline instead of using
// a predefined one.
/*
{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["HelloWorld.ts"],
"showOutput": "silent",
"problemMatcher": {
// The problem is owned by the typescript language service. Ensure that the problems
// are merged with problems produced by Visual Studio's language service.
"owner": "typescript",
// The file name for reported problems is relative to the current working directory.
"fileLocation": ["relative", "${cwd}"],
// The actual pattern to match problems in the output.
"pattern": {
// The regular expression. Matches HelloWorld.ts(2,10): error TS2339: Property 'logg' does not exist on type 'Console'.
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
// The match group that denotes the file containing the problem.
"file": 1,
// The match group that denotes the problem location.
"location": 2,
// The match group that denotes the problem's severity. Can be omitted.
"severity": 3,
// The match group that denotes the problem code. Can be omitted.
"code": 4,
// The match group that denotes the problem's message.
"message": 5
}
}
}
*/
2 changes: 2 additions & 0 deletions bin/cli
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/main.js');
2 changes: 2 additions & 0 deletions bin/cli-config
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-config.js');
2 changes: 2 additions & 0 deletions bin/cli-create-workspace
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-create-workspace.js');
2 changes: 2 additions & 0 deletions bin/cli-get-datasets
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-get-datasets.js');
2 changes: 2 additions & 0 deletions bin/cli-get-workspaces
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-get-workspaces.js');
2 changes: 2 additions & 0 deletions bin/cli-import
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-import.js');
2 changes: 2 additions & 0 deletions bin/cli-update-connection
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../lib/cli-update-workspaces.js');
1 change: 1 addition & 0 deletions index.ts
@@ -0,0 +1 @@
export * from "./lib/main";
6 changes: 6 additions & 0 deletions jsconfig.json
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs"
}
}
1 change: 1 addition & 0 deletions lib.powerbirc
@@ -0,0 +1 @@
{"collection":"foobar2"}
50 changes: 50 additions & 0 deletions lib/cli-config.ts
@@ -0,0 +1,50 @@
/// <reference path="../typings/main.d.ts" />
'use strict';
import * as powerbi from 'powerbi-api';
import * as msrest from 'ms-rest';
import {Cli as cli} from './cli';
import * as fs from 'fs';
import {Config as config} from './config';

export module 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 MyWorkspace -k ABC123 -w ABC123');
});

program.parse(process.argv);

try {
let properties = ['collection', 'workspace', 'accessKey', 'baseUri'];

let currentConfig = config.get();

for (let i = 0; i < properties.length; i++) {
if (program[properties[i]]) {
currentConfig[properties[i]] = program[properties[i]];
}
}

config.set(currentConfig);

for (var key in currentConfig) {
cli.print({ message: util.format('%s: %s', key, currentConfig[key]) });
}
} catch (err) {
cli.error(err);
}
}
51 changes: 51 additions & 0 deletions lib/cli-create-workspace.ts
@@ -0,0 +1,51 @@
/// <reference path="../typings/main.d.ts" />

'use strict';
import * as powerbi from 'powerbi-api';
import * as msrest from 'ms-rest';
import {Cli as cli} from './cli';
import {Config as config} from './config';

export module CreateWorkspace {
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 MyWorkspace -k ABC123');
});

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) {
cli.error(err);
} else {
cli.print({ message: util.format('Workspace created: %s', result.workspaceId) });
}
});
} catch (_error) {
err = _error;
cli.error({ message: err });
}
}
}

0 comments on commit 1d26221

Please sign in to comment.