-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
72 lines (55 loc) · 2.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
var program = require("commander");
var fs = require("fs");
program
.version(require('./package').version);
program
.option('-d, --directory [directory]', 'Directory where all non-uniquely-named artifacts are generated. Default: minus -topology.json')
.option('-u, --ansible_user [ansible_user]', 'Ansible User Name')
.option('-k, --ansible_key [ansible_key]', 'Ansible SSH Private Key File')
.command("generate <artifact> <topology> [<output>]").alias("g")
.description('Generate artifact')
.action(function (artifact, topology, output) {
artifactType = artifact || "<notprovided>";
topologyFile = topology;
outputFile = output || 'con';
program.directory = program.directory || topologyFile.replace( /-topology\.json$/, "" );
});
program.on('*', function () {
console.log('Unknown Command: ' + program.args.join(' '));
program.help();
})
var supportedArtifactTypes = ["diagram", "portrequest", "checkports", "inventory", "consulconnect"];
program.on('--help', function () {
console.log(' Supported artifact: ' + supportedArtifactTypes.join(", "));
console.log('');
});
program.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
process.exit(1);
}
if (supportedArtifactTypes.indexOf(artifactType) == -1) {
console.error(`The artifact '${artifactType}' is not supported.`);
process.exit(1);
}
// create an output directory for generated artifacts
if (!fs.existsSync( program.directory )){
fs.mkdirSync( program.directory );
}
//console.log(artifactType);
//console.log(topologyFile);
//console.log(outputFile);
if( artifactType === "portrequest"){
var generatePortRequest = require( "./generatePortRequest.js" );
generatePortRequest(topologyFile, outputFile, program);
}else if (artifactType === "diagram" ){
var generateSvgDiagram = require( "./generateSvgDiagram.js" );
generateSvgDiagram(topologyFile, outputFile);
}else if (artifactType === "inventory" ){
var generateInventory = require( "./generateInventory.js" );
generateInventory(topologyFile, outputFile, program);
}else if (artifactType === "consulconnect" ){
var generateConsulConnect = require( "./generateConsulConnect.js" );
generateConsulConnect(topologyFile, outputFile, program);
}