Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
added 'handleAs' setting for entries in prompt targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Aug 21, 2017
1 parent 1b7445e commit fe60e43
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log (vs-deploy)

## 9.31.0 (August 21st, 2017; prompt target)

* added `handleAs` property for entries in a [prompt target](https://github.com/mkloubert/vs-deploy/wiki/target_prompt), which can define in what data type to convert the user's input to

## 9.30.0 (August 12th, 2017; output results of SFTP commands)

* can output results of [SFTP server commands](https://github.com/mkloubert/vs-deploy/wiki/target_sftp#execute-commands-on-server) defined in `beforeUpload`, `closing`, `connected` and `uploaded` settings now
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vs-deploy",
"displayName": "Deploy",
"description": "Commands for deploying files of your workspace to a destination.",
"version": "9.30.0",
"version": "9.31.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.6.0"
Expand Down Expand Up @@ -19851,6 +19851,12 @@
"type": "boolean",
"default": true
},
"handleAs": {
"description": "The type to convert the user's input to.",
"type": "string",
"enum": [ "", "list", "object", "string" ],
"default": "string"
},
"isPassword": {
"description": "Input value is secret / a password.",
"type": "boolean",
Expand Down
30 changes: 26 additions & 4 deletions src/plugins/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface PromptEntry {
validator?: string;
validatorOptions?: any;
valuePlaceHolder?: string;
handleAs?: string;
}

/**
Expand Down Expand Up @@ -205,7 +206,7 @@ class PromptPlugin extends deploy_objects.MultiFileDeployPluginBase {
};
});

// create an actio
// create an action
// for each entry in
// 'prompts'
prompts.forEach((p, propmptIndex) => {
Expand Down Expand Up @@ -335,7 +336,7 @@ class PromptPlugin extends deploy_objects.MultiFileDeployPluginBase {
}

return new Promise<any>((resolve, reject) => {
let completed = (err: any, userValue?: string) => {
let completed = (err: any, userValue?: any) => {
if (err) {
reject(err);
}
Expand Down Expand Up @@ -422,6 +423,21 @@ class PromptPlugin extends deploy_objects.MultiFileDeployPluginBase {
placeHolderText = deploy_values.replaceWithValues(me.context.values(), placeHolderText);
placeHolderText = !deploy_helpers.isEmptyString(placeHolderText) ? placeHolderText : undefined;

const CONVERT_INPUT_VALUE = (inputVal: string): any => {
switch (deploy_helpers.normalizeString(p.handleAs)) {
case 'list':
return JSON.parse('[ ' + inputVal + ' ]');

case 'object':
if (deploy_helpers.isEmptyString(inputVal)) {
return undefined;
}
return JSON.parse(inputVal);
}

return inputVal;
};

vscode.window.showInputBox({
ignoreFocusOut: ignoreFocusOut,
password: deploy_helpers.toBooleanSafe(p.isPassword),
Expand All @@ -445,7 +461,7 @@ class PromptPlugin extends deploy_objects.MultiFileDeployPluginBase {
return me.context.require(id);
},
targets: targets,
value: v,
value: CONVERT_INPUT_VALUE(v),
};

let isValid = deploy_helpers.toBooleanSafe(validator(args), true);
Expand All @@ -468,7 +484,13 @@ class PromptPlugin extends deploy_objects.MultiFileDeployPluginBase {
return errMsg;
},
}).then((userValue) => {
completed(null, userValue);
try {
completed(null,
CONVERT_INPUT_VALUE(userValue));
}
catch (e) {
completed(e);
}
}, (err) => {
completed(err);
});
Expand Down

0 comments on commit fe60e43

Please sign in to comment.