From 52ce79850fc9990704e7a2f33fef67619ec352f2 Mon Sep 17 00:00:00 2001 From: LeWarEnds Date: Thu, 6 Dec 2018 23:30:15 +0530 Subject: [PATCH 1/5] Add Command Registration through Read Directory method --- bin/clocal-gcp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bin/clocal-gcp b/bin/clocal-gcp index e5736df..a2e8fea 100755 --- a/bin/clocal-gcp +++ b/bin/clocal-gcp @@ -3,18 +3,23 @@ 'use strict'; const program = require('commander'); - +const FunctionalArray = require('../src/serviceCounter/API') const commandsArray = require('../src/services/index').commands; - program.version('1.0.0').description('Clocal GCP'); -const commandNameList = []; - -commandsArray.map(command => { +let length = items.length; +for(var i = 0; i < length;i++){ + const ServicesCmdBash = require('../src/services/cli-commands/'+items[i]+'/cmd'); + commandsArray = [ServicesCmdBash]; + program.version().description('Clocal GCP'); + + const commandNameList = [FunctionalArray]; + commandsArray.map(command => { commandNameList.push(command.commandName); program.command(command.commandName).action(command.action); }); - +} + program.command('list').action(() => { const commandNames = commandNameList.reduce((prev, current) => { return `${prev}\n${current}`; From 9ce6e55745c05e29fa3c26f9dc0f967365ba8de2 Mon Sep 17 00:00:00 2001 From: LeWarEnds Date: Sat, 8 Dec 2018 08:26:09 +0530 Subject: [PATCH 2/5] Done Required Changes. I have done the required changes told by TheLukaszNs. Thanks --- bin/clocal-gcp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/clocal-gcp b/bin/clocal-gcp index a2e8fea..3248ccf 100755 --- a/bin/clocal-gcp +++ b/bin/clocal-gcp @@ -3,7 +3,6 @@ 'use strict'; const program = require('commander'); -const FunctionalArray = require('../src/serviceCounter/API') const commandsArray = require('../src/services/index').commands; program.version('1.0.0').description('Clocal GCP'); @@ -11,10 +10,10 @@ let length = items.length; for(var i = 0; i < length;i++){ const ServicesCmdBash = require('../src/services/cli-commands/'+items[i]+'/cmd'); commandsArray = [ServicesCmdBash]; - program.version().description('Clocal GCP'); + program.version('1.0.0').description('Clocal GCP'); const commandNameList = [FunctionalArray]; - commandsArray.map(command => { + commandsArray.forEach(command => { commandNameList.push(command.commandName); program.command(command.commandName).action(command.action); }); From f67cfb464705c20d11d1a0af32249d3575f3be18 Mon Sep 17 00:00:00 2001 From: LeWarEnds Date: Sat, 8 Dec 2018 08:57:10 +0530 Subject: [PATCH 3/5] Update changes. --- bin/clocal-gcp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/clocal-gcp b/bin/clocal-gcp index 3248ccf..d81539d 100755 --- a/bin/clocal-gcp +++ b/bin/clocal-gcp @@ -3,16 +3,17 @@ 'use strict'; const program = require('commander'); -const commandsArray = require('../src/services/index').commands; +const commandsArray =[]; program.version('1.0.0').description('Clocal GCP'); +fs.readdir(originpath, function(err, items) { let length = items.length; for(var i = 0; i < length;i++){ const ServicesCmdBash = require('../src/services/cli-commands/'+items[i]+'/cmd'); commandsArray = [ServicesCmdBash]; program.version('1.0.0').description('Clocal GCP'); - const commandNameList = [FunctionalArray]; + const commandNameList = []; commandsArray.forEach(command => { commandNameList.push(command.commandName); program.command(command.commandName).action(command.action); From e10dd731324f8811108194354c30effbe63fb951 Mon Sep 17 00:00:00 2001 From: LeWarEnds Date: Sat, 8 Dec 2018 19:22:27 +0530 Subject: [PATCH 4/5] Update Changes. --- bin/clocal-gcp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bin/clocal-gcp b/bin/clocal-gcp index d81539d..76a3998 100755 --- a/bin/clocal-gcp +++ b/bin/clocal-gcp @@ -3,23 +3,28 @@ 'use strict'; const program = require('commander'); +const fs = require('fs'); +const path = require('path'); +let length = items.length; + const commandsArray =[]; -program.version('1.0.0').description('Clocal GCP'); +const commandNameList = []; +const commandsDirectory = path.join(__dirname, '../src/services/cli-commands'); + +program.version('1.0.0').description('Clocal GCP'); fs.readdir(originpath, function(err, items) { -let length = items.length; + for(var i = 0; i < length;i++){ const ServicesCmdBash = require('../src/services/cli-commands/'+items[i]+'/cmd'); - commandsArray = [ServicesCmdBash]; - program.version('1.0.0').description('Clocal GCP'); + const directories = fs.readdirSync(commandsDirectory); - const commandNameList = []; commandsArray.forEach(command => { - commandNameList.push(command.commandName); - program.command(command.commandName).action(command.action); -}); + commandNameList.push(command.commandName); + program.command(command.commandName).action(command.action); + }); } - + program.command('list').action(() => { const commandNames = commandNameList.reduce((prev, current) => { return `${prev}\n${current}`; From 95b8e5829184db4c34256320eb2b47d040feb155 Mon Sep 17 00:00:00 2001 From: LeWarEnds Date: Sat, 8 Dec 2018 20:28:32 +0530 Subject: [PATCH 5/5] Update Required Changes. --- bin/clocal-gcp | 63 ++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/bin/clocal-gcp b/bin/clocal-gcp index 76a3998..99b98b1 100755 --- a/bin/clocal-gcp +++ b/bin/clocal-gcp @@ -1,35 +1,32 @@ -#!/usr/bin/env node - -'use strict'; - -const program = require('commander'); -const fs = require('fs'); -const path = require('path'); -let length = items.length; - -const commandsArray =[]; -const commandNameList = []; -const commandsDirectory = path.join(__dirname, '../src/services/cli-commands'); - -program.version('1.0.0').description('Clocal GCP'); - -fs.readdir(originpath, function(err, items) { - -for(var i = 0; i < length;i++){ - const ServicesCmdBash = require('../src/services/cli-commands/'+items[i]+'/cmd'); - const directories = fs.readdirSync(commandsDirectory); +const fs = require('fs'); +const program = require('commander'); +const main = process.cwd() + "/src/services/cli-commands/"; +let commandsArray = []; +const commandNameList = []; + +program.version('1.0.0').description('Clocal GCP'); + +fs.readdir(main, function(err, items) { + var totalImports = items.length + while (i >= totalImports) { + + const required = require('../src/services/cli-commands/'+items[i]+'/cmd'); + commandsArray = [required]; + + commandsArray.map(command => { + commandNameList.push(command.commandName); + program.command(command.commandName).action(command.action); + }); + i++; + } - commandsArray.forEach(command => { - commandNameList.push(command.commandName); - program.command(command.commandName).action(command.action); - }); -} - -program.command('list').action(() => { - const commandNames = commandNameList.reduce((prev, current) => { - return `${prev}\n${current}`; - }, ''); + program.command('list').action(() => { + const commandNames = commandNameList.reduce((prev, current) => { + return `${prev}\n${current}`; + }, ''); + console.log(commandNameList.toString()); -}); - -program.parse(process.argv); + }); + + program.parse(process.argv); +});