bpoole16 commented on a change in pull request #2334: (Review) Added --last 
Activation Flag 
URL: 
https://github.com/apache/incubator-openwhisk/pull/2334#discussion_r124833665
 
 

 ##########
 File path: tools/cli/go-whisk-cli/commands/activation.go
 ##########
 @@ -216,6 +240,47 @@ var activationResultCmd = &cobra.Command{
     },
 }
 
+// lastFlag(args) retrieves the last activation with flag -l or --last
+// Param: Brings in []strings from args
+// Return: Returns a []string with the latest ID or the original args and any 
errors
+func lastFlag(args []string) ([]string, error) {
+  // Checks to see if there is an ID sent with the --last
+  // If an ID is given with --last then an error will be thrown
+  if  flags.activation.last {
+    options := &whisk.ActivationListOptions {
+      Limit: 1,
+      Skip: 0,
+    }
+    activations,_, err := client.Activations.List(options)
+    if err != nil {   // Checks Activations.List for errors when retrieving 
latest activaiton
+      whisk.Debug(whisk.DbgError, "client.Activations.List() error for flag 
--last: %s\n", err)
+      return args, err
+    }
+    if len(activations) == 0 {    // Checks to to see if there are activations 
available
+      whisk.Debug(whisk.DbgError, "No activations found in activation list\n")
+      errStr := wski18n.T("Activation list contains no activations")
+      whiskErr := whisk.MakeWskError(errors.New(errStr), 
whisk.EXITCODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
+      return args, whiskErr
+    } else {
+      if len(args) == 0 {
+        whisk.Debug(whisk.DbgInfo, "Appending most recent activation ID into 
args\n")
+        args = append(args, activations[0].ActivationID)
+      } else if _,_,err := client.Activations.Get(args[0]); len(args) == 1 && 
err != nil{   // Checks to see if filter field is given and not ID
+          whisk.Debug(whisk.DbgInfo, "Appending most recent activation ID into 
args\n")
+          args = append(args, activations[0].ActivationID)
+          whisk.Debug(whisk.DbgInfo, "Allocating appended ID to correct 
position in args\n")
+          args[0], args[1] = args[1], args[0]   // IDs should be located at 
args[0], if a filter field is given it has to be moved to args[0]
+      } else if _,_,err := client.Activations.Get(args[0]);  len(args) >= 1 && 
err == nil {    // Checks conflict between ID, field filter and --last
 
 Review comment:
   I could do a for loop or something checking the length of the arguments to 
see if they are an ID (length of 32) or filter field (any length). The point of 
the system calls were to check if they were returning errors due to filter 
field being sent instead of ID. 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to