Socket
Socket
Sign inDemoInstall

@microsoft/ts-command-line

Package Overview
Dependencies
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/ts-command-line - npm Package Compare versions

Comparing version 3.0.7 to 3.1.0

dist/index-preview.d.ts

15

CHANGELOG.json

@@ -5,2 +5,17 @@ {

{
"version": "3.1.0",
"tag": "@microsoft/ts-command-line_v3.1.0",
"date": "Thu, 15 Mar 2018 20:00:50 GMT",
"comments": {
"minor": [
{
"comment": "Add default error handler so the caller to CommandLineParser.execute() is not expected to handle promise rejections"
},
{
"comment": "Add a new API \"CommandLineParser.executeWithoutErrorHandling()\""
}
]
}
},
{
"version": "3.0.7",

@@ -7,0 +22,0 @@ "tag": "@microsoft/ts-command-line_v3.0.7",

10

CHANGELOG.md
# Change Log - @microsoft/ts-command-line
This log was last generated on Mon, 12 Mar 2018 20:36:19 GMT and should not be manually modified.
This log was last generated on Thu, 15 Mar 2018 20:00:50 GMT and should not be manually modified.
## 3.1.0
Thu, 15 Mar 2018 20:00:50 GMT
### Minor changes
- Add default error handler so the caller to CommandLineParser.execute() is not expected to handle promise rejections
- Add a new API "CommandLineParser.executeWithoutErrorHandling()"
## 3.0.7

@@ -6,0 +14,0 @@ Mon, 12 Mar 2018 20:36:19 GMT

@@ -188,10 +188,25 @@ /**

/**
* This is the main entry point to begin parsing command-line arguments
* The program entry point will call this method to begin parsing command-line arguments
* and executing the corresponding action.
*
* @param args the command-line arguments to be parsed; if omitted, then
* @remarks
* The returned promise will never reject: If an error occurs, it will be printed
* to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
* This simplifies the most common usage scenario where the program entry point doesn't
* want to be involved with the command-line logic, and will discard the promise without
* a then() or catch() block.
*
* If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}
* instead.
*
* @param args - the command-line arguments to be parsed; if omitted, then
* the process.argv will be used
*/
execute(args?: string[]): Promise<void>;
execute(args?: string[]): Promise<boolean>;
/**
* This is similar to {@link CommandLineParser.execute}, except that execution errors
* simply cause the promise to reject. It is the caller's responsibility to trap
*/
executeWithoutErrorHandling(args?: string[]): Promise<void>;
/**
* This hook allows the subclass to perform additional operations before or after

@@ -198,0 +213,0 @@ * the chosen action is executed.

7

lib/CommandLineAction.js

@@ -41,8 +41,3 @@ "use strict";

_execute() {
try {
return this.onExecute();
}
catch (error) {
return Promise.reject(error);
}
return this.onExecute();
}

@@ -49,0 +44,0 @@ }

@@ -43,10 +43,25 @@ import CommandLineAction from './CommandLineAction';

/**
* This is the main entry point to begin parsing command-line arguments
* The program entry point will call this method to begin parsing command-line arguments
* and executing the corresponding action.
*
* @param args the command-line arguments to be parsed; if omitted, then
* @remarks
* The returned promise will never reject: If an error occurs, it will be printed
* to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
* This simplifies the most common usage scenario where the program entry point doesn't
* want to be involved with the command-line logic, and will discard the promise without
* a then() or catch() block.
*
* If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}
* instead.
*
* @param args - the command-line arguments to be parsed; if omitted, then
* the process.argv will be used
*/
execute(args?: string[]): Promise<void>;
execute(args?: string[]): Promise<boolean>;
/**
* This is similar to {@link CommandLineParser.execute}, except that execution errors
* simply cause the promise to reject. It is the caller's responsibility to trap
*/
executeWithoutErrorHandling(args?: string[]): Promise<void>;
/**
* This hook allows the subclass to perform additional operations before or after

@@ -53,0 +68,0 @@ * the chosen action is executed.

@@ -44,30 +44,59 @@ "use strict";

/**
* This is the main entry point to begin parsing command-line arguments
* The program entry point will call this method to begin parsing command-line arguments
* and executing the corresponding action.
*
* @param args the command-line arguments to be parsed; if omitted, then
* @remarks
* The returned promise will never reject: If an error occurs, it will be printed
* to stderr, process.exitCode will be set to 1, and the promise will resolve to false.
* This simplifies the most common usage scenario where the program entry point doesn't
* want to be involved with the command-line logic, and will discard the promise without
* a then() or catch() block.
*
* If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling}
* instead.
*
* @param args - the command-line arguments to be parsed; if omitted, then
* the process.argv will be used
*/
execute(args) {
if (!args) {
// 0=node.exe, 1=script name
args = process.argv.slice(2);
}
if (args.length === 0) {
this._argumentParser.printHelp();
return Promise.resolve();
}
const data = this._argumentParser.parseArgs();
this._processParsedData(data);
for (const action of this._actions) {
if (action.options.actionVerb === data.action) {
this.selectedAction = action;
action._processParsedData(data);
break;
return this.executeWithoutErrorHandling(args).then(() => {
return true;
}).catch((e) => {
const message = (e.message || 'An unknown error occurred').trim();
console.error(colors.red('Error: ' + message));
process.exitCode = 1;
return false;
});
}
/**
* This is similar to {@link CommandLineParser.execute}, except that execution errors
* simply cause the promise to reject. It is the caller's responsibility to trap
*/
executeWithoutErrorHandling(args) {
try {
if (!args) {
// 0=node.exe, 1=script name
args = process.argv.slice(2);
}
if (args.length === 0) {
this._argumentParser.printHelp();
return Promise.resolve();
}
const data = this._argumentParser.parseArgs();
this._processParsedData(data);
for (const action of this._actions) {
if (action.options.actionVerb === data.action) {
this.selectedAction = action;
action._processParsedData(data);
break;
}
}
if (!this.selectedAction) {
throw Error('Unrecognized action');
}
return this.onExecute();
}
if (!this.selectedAction) {
throw Error('Unrecognized action');
catch (error) {
return Promise.reject(error);
}
return this.onExecute();
}

@@ -74,0 +103,0 @@ /**

{
"name": "@microsoft/ts-command-line",
"version": "3.0.7",
"version": "3.1.0",
"description": "An object-oriented command-line parser for TypeScript",

@@ -26,4 +26,4 @@ "repository": {

"mocha": "~3.4.2",
"@microsoft/node-library-build": "4.3.13"
"@microsoft/node-library-build": "4.3.20"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc