Skip to content

Commit

Permalink
feat(add-credentials): add credentials command
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna-acondy committed Nov 30, 2020
1 parent b9d7227 commit b23953b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"@sasjs/adapter": "^1.18.7",
"@sasjs/core": "^1.11.2",
"@sasjs/utils": "file:../utils/build/sasjs-utils-5.0.0.tgz",
"base64-img": "^1.0.4",
"btoa": "^1.2.1",
"chalk": "^4.1.0",
Expand Down
6 changes: 6 additions & 0 deletions src/commands/add-cred.ts
@@ -0,0 +1,6 @@
import { Logger, LogLevel } from '@sasjs/utils/logger/index'

export const addCredential = async (targetName: string): Promise<void> => {
const logger = new Logger(LogLevel.Debug)
logger.info(`You are here: ${targetName}`)
}
1 change: 1 addition & 0 deletions src/commands/index.js
@@ -1,4 +1,5 @@
export { addTarget } from './add'
export { addCredential } from './add-cred'

export {
build,
Expand Down
42 changes: 33 additions & 9 deletions src/main.js
@@ -1,4 +1,5 @@
import {
addCredential,
addTarget,
build,
processContext,
Expand Down Expand Up @@ -288,18 +289,41 @@ export async function buildWebApp(commandLine) {

export async function add(commandLine) {
const command = new Command(commandLine)
const subCommand = command.getSubCommand()
let targetName = command.getFlagValue('target')

if (!targetName) {
targetName = command.getTargetWithoutFlag()
}

let result = false

if (command && command.name === 'add') {
await addTarget()
.then(() => {
console.log(chalk.greenBright('Target successfully added!'))
result = true
})
.catch((err) => {
displayResult(err, 'An error has occurred when adding the target.')
result = err
})
if (subCommand === 'cred') {
await addCredential(targetName)
.then(() => {
console.log(chalk.greenBright('Credential successfully added!'))
result = true
})
.catch((err) => {
console.log(err)
displayResult(
err,
'An error has occurred when adding the credential.'
)
result = err
})
} else if (subCommand === 'target' || !subCommand) {
await addTarget()
.then(() => {
console.log(chalk.greenBright('Target successfully added!'))
result = true
})
.catch((err) => {
displayResult(err, 'An error has occurred when adding the target.')
result = err
})
}
}

return result
Expand Down
1 change: 1 addition & 0 deletions src/utils/command.js
Expand Up @@ -78,6 +78,7 @@ const commandFlags = [
command: initialCommands.context,
flags: [initialFlags.target, initialFlags.source]
},
{ command: initialCommands.add, flags: [initialFlags.target] },
{ command: initialCommands.create, flags: [initialFlags.template] },
{ command: initialCommands.web, flags: [initialFlags.target] },
{ command: initialCommands['build-DB'], flags: [initialFlags.target] },
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -3,6 +3,7 @@
"target": "es5",
"allowJs": true,
"module": "commonjs",
"moduleResolution": "node",
"downlevelIteration": true,
"lib": [
"ES2018",
Expand Down

0 comments on commit b23953b

Please sign in to comment.