Repository: serverless/serverless (JavaScript)
Date: 2020-04-30 23:21:24+00:00
Task type: Bug Fix

Issue:
sls rollback function does not recognize version input
Hi,

Appreciate any feedback on this. Is it a known bug or something wrong with the way i execute 
this command?
`sls rollback function --function -f test-sls-rollback-dev-hello --version 8`

returns error:
` "8" is not a valid sub command. Run "serverless rollback function" to see a more helpful error message for this command.`

serverless framework details:
-   Operating System:          linux
-      Node Version:              10.19.0
-      Framework Version:         1.69.0
-      Plugin Version:            3.6.9
-      SDK Version:               2.3.0
-      Components Version:        2.30.4


Issue discussion:
@aizulhussin great thanks for that report.

Technically it's a bug, that's a side effect result of applying fix for other bug here: https://github.com/serverless/serverless/pull/7131

Situation now is, that `--version` conflicts with core `--version` param, which is boolean (a request to show version of a framework)

Real fix for that would be to rename `--version` param of this command into `--function-version`
PR that fixes that is welcome.

It should be as easy as updating this internal plugin: https://github.com/serverless/serverless/blob/bd9fbfb392afc2dc95f7d83864bfdc4dc1602728/lib/plugins/aws/rollbackFunction/index.js
I would like to apply that fix
@AhmedFat7y that'll be great, thank you!

Solution patch:
diff --git a/docs/providers/aws/cli-reference/rollback-function.md b/docs/providers/aws/cli-reference/rollback-function.md
index 6a398bb6442..8b25f46f133 100644
--- a/docs/providers/aws/cli-reference/rollback-function.md
+++ b/docs/providers/aws/cli-reference/rollback-function.md
@@ -17,7 +17,7 @@ layout: Doc
 Rollback a function service to a specific version.
 
 ```bash
-serverless rollback function --function <name> --version <version>
+serverless rollback function --function <name> --function-version <version>
 ```
 
 **Note:** You can only rollback a function which was previously deployed through `serverless deploy`. Functions are not versioned when running `serverless deploy function`.
@@ -25,7 +25,7 @@ serverless rollback function --function <name> --version <version>
 ## Options
 
 - `--function` or `-f` The name of the function which should be rolled back
-- `--version` or `-v` The version to which the function should be rolled back
+- `--function-version` or `-v` The version to which the function should be rolled back
 
 ## Examples
 
diff --git a/lib/plugins/aws/rollbackFunction/index.js b/lib/plugins/aws/rollbackFunction/index.js
index 6306a94ead2..b522b354677 100644
--- a/lib/plugins/aws/rollbackFunction/index.js
+++ b/lib/plugins/aws/rollbackFunction/index.js
@@ -19,21 +19,21 @@ class AwsRollbackFunction {
             usage: 'Rollback the function to a specific version',
             lifecycleEvents: ['rollback'],
             options: {
-              function: {
+              'function': {
                 usage: 'Name of the function',
                 shortcut: 'f',
                 required: true,
               },
-              version: {
+              'function-version': {
                 usage: 'Version of the function',
                 shortcut: 'v',
                 required: true,
               },
-              stage: {
+              'stage': {
                 usage: 'Stage of the function',
                 shortcut: 's',
               },
-              region: {
+              'region': {
                 usage: 'Region of the function',
                 shortcut: 'r',
               },
@@ -55,10 +55,10 @@ class AwsRollbackFunction {
 
   getFunctionToBeRestored() {
     const funcName = this.options.function;
-    let funcVersion = this.options.version;
+    let funcVersion = this.options['function-version'];
 
     // versions need to be string so that AWS understands it
-    funcVersion = String(this.options.version);
+    funcVersion = String(this.options['function-version']);
 
     this.serverless.cli.log(`Rolling back function "${funcName}" to version "${funcVersion}"...`);
 
diff --git a/lib/plugins/rollback/index.js b/lib/plugins/rollback/index.js
index 93c40209327..bea6109e7ef 100644
--- a/lib/plugins/rollback/index.js
+++ b/lib/plugins/rollback/index.js
@@ -28,21 +28,21 @@ class Rollback {
             usage: 'Rollback the function to the previous version',
             lifecycleEvents: ['rollback'],
             options: {
-              function: {
+              'function': {
                 usage: 'Name of the function',
                 shortcut: 'f',
                 required: true,
               },
-              version: {
+              'function-version': {
                 usage: 'Version of the function',
                 shortcut: 'v',
                 required: true,
               },
-              stage: {
+              'stage': {
                 usage: 'Stage of the function',
                 shortcut: 's',
               },
-              region: {
+              'region': {
                 usage: 'Region of the function',
                 shortcut: 'r',
               },


Test patch:
diff --git a/lib/plugins/aws/rollbackFunction/index.test.js b/lib/plugins/aws/rollbackFunction/index.test.js
index 4663994f1ae..147dad7a59e 100644
--- a/lib/plugins/aws/rollbackFunction/index.test.js
+++ b/lib/plugins/aws/rollbackFunction/index.test.js
@@ -101,7 +101,7 @@ describe('AwsRollbackFunction', () => {
 
       it('should return the requested function', () => {
         awsRollbackFunction.options.function = 'hello';
-        awsRollbackFunction.options.version = '4711';
+        awsRollbackFunction.options['function-version'] = '4711';
 
         return awsRollbackFunction.getFunctionToBeRestored().then(result => {
           expect(getFunctionStub.calledOnce).to.equal(true);
@@ -132,7 +132,7 @@ describe('AwsRollbackFunction', () => {
 
       it('should translate the error message to a custom error message', () => {
         awsRollbackFunction.options.function = 'hello';
-        awsRollbackFunction.options.version = '4711';
+        awsRollbackFunction.options['function-version'] = '4711';
 
         return awsRollbackFunction.getFunctionToBeRestored().catch(error => {
           expect(error.message.match(/Function "hello" with version "4711" not found/));
@@ -163,7 +163,7 @@ describe('AwsRollbackFunction', () => {
 
       it('should re-throw the error without translating it to a custom error message', () => {
         awsRollbackFunction.options.function = 'hello';
-        awsRollbackFunction.options.version = '4711';
+        awsRollbackFunction.options['function-version'] = '4711';
 
         return awsRollbackFunction.getFunctionToBeRestored().catch(error => {
           expect(error.message.match(/something went wrong/));