diff --git a/docs/actions.md b/docs/actions.md index 74cb16d5b9e..539db7d0f66 100644 --- a/docs/actions.md +++ b/docs/actions.md @@ -1027,6 +1027,19 @@ You can list all the actions that you have created using `wsk action list`: ``` wsk action list actions +/guest/packageB/A private nodejs:6 +/guest/C private nodejs:6 +/guest/A private nodejs:6 +/guest/packageA/B private nodejs:6 +/guest/packageA/A private nodejs:6 +/guest/B private nodejs:6 +``` + +Here, we see actions listed in order from most to least recently updated. For easier browsing, you can use the flag `--name-sort` or `-n` to sort a list alphabetically: + +``` +wsk action list --name-sort +actions /guest/A private nodejs:6 /guest/B private nodejs:6 /guest/C private nodejs:6 @@ -1035,11 +1048,11 @@ actions /guest/packageB/A private nodejs:6 ``` -Here, we see actions listed in alphabetical order from namespace to package name to action name, with the default package (no specified package) listed at the top. +Notice that the list is now sorted alphabetically by namespace, then package name, and finally action name, with the default package (no specified package) listed at the top. **Note**: The printed list is sorted alphabetically after it is received from the server. Other list flags such as `--limit` and `--skip` will be applied to the block of actions before they are received for sorting. To list actions in order by creation time, use the flag `--time`. -As you write more actions, this list gets longer and it can be helpful to group related actions into [packages](./packages.md). To filter your list of actions to just the those within a specific pacakge, you can use: +As you write more actions, this list gets longer and it can be helpful to group related actions into [packages](./packages.md). To filter your list of actions to just the those within a specific package, you can use: ``` wsk action list [PACKAGE NAME] diff --git a/docs/apigateway.md b/docs/apigateway.md index 5708168ead5..609656d4e8f 100644 --- a/docs/apigateway.md +++ b/docs/apigateway.md @@ -123,12 +123,6 @@ wsk api list -f ``` ``` ok: APIs -Action: deleteBooks - API Name: Book Club - Base path: /club - Path: /books - Verb: delete - URL: https://${APIHOST}:9001/api/21ef035/club/books Action: getBooks API Name: Book Club Base path: /club @@ -147,10 +141,14 @@ Action: putBooks Path: /books Verb: put URL: https://${APIHOST}:9001/api/21ef035/club/books +Action: deleteBooks + API Name: Book Club + Base path: /club + Path: /books + Verb: delete + URL: https://${APIHOST}:9001/api/21ef035/club/books ``` -**Note**: APIs are sorted alphabetically (by order of `Base Path`, then `Path`, and then `Verb`) by default. To sort the list by creation time, you can use the flag `--time`. - Now just for fun let's add a new book `JavaScript: The Good Parts` with a HTTP __POST__ ``` curl -X POST -d '{"name":"JavaScript: The Good Parts", "isbn":"978-0596517748"}' https://${APIHOST}:9001/api/21ef035/club/books @@ -213,8 +211,8 @@ wsk api list /club ``` ok: apis Action Verb API Name URL -deleteBooks delete Book Club https://${APIHOST}:9001/api/21ef035/club/books getBooks get Book Club https://${APIHOST}:9001/api/21ef035/club/books postBooks post Book Club https://${APIHOST}:9001/api/21ef035/club/books putBooks put Book Club https://${APIHOST}:9001/api/21ef035/club/books +deleteBooks delete Book Club https://${APIHOST}:9001/api/21ef035/club/books ``` diff --git a/docs/packages.md b/docs/packages.md index 05bcf924200..499c2478d57 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -22,17 +22,17 @@ Several packages are registered with OpenWhisk. You can get a list of packages i ``` ``` packages - /whisk.system/alarms shared /whisk.system/cloudant shared - /whisk.system/github shared - /whisk.system/pushnotifications shared - /whisk.system/samples shared - /whisk.system/slack shared - /whisk.system/system shared + /whisk.system/alarms shared /whisk.system/watson shared - /whisk.system/weather shared /whisk.system/websocket shared + /whisk.system/weather shared + /whisk.system/system shared /whisk.system/utils shared + /whisk.system/slack shared + /whisk.system/samples shared + /whisk.system/github shared + /whisk.system/pushnotifications shared ``` 2. Get a list of entities in the `/whisk.system/cloudant` package. diff --git a/tests/src/test/scala/common/Wsk.scala b/tests/src/test/scala/common/Wsk.scala index 726e964da32..1aa931367be 100644 --- a/tests/src/test/scala/common/Wsk.scala +++ b/tests/src/test/scala/common/Wsk.scala @@ -144,12 +144,12 @@ trait ListOrGetFromCollection extends FullyQualifiedNames { def list( namespace: Option[String] = None, limit: Option[Int] = None, - time: Option[Boolean] = None, + nameSort: Option[Boolean] = None, expectedExitCode: Int = SUCCESS_EXIT)( implicit wp: WskProps): RunResult = { val params = Seq(noun, "list", resolve(namespace), "--auth", wp.authKey) ++ { limit map { l => Seq("--limit", l.toString) } getOrElse Seq() } ++ - { time map { t => Seq("--time") } getOrElse Seq() } + { nameSort map { n => Seq("--name-sort") } getOrElse Seq() } cli(wp.overrides ++ params, expectedExitCode) } @@ -694,10 +694,10 @@ class WskNamespace() */ def list( expectedExitCode: Int = SUCCESS_EXIT, - time: Option[Boolean] = None)( + nameSort: Option[Boolean] = None)( implicit wp: WskProps): RunResult = { val params = Seq(noun, "list", "--auth", wp.authKey) ++ - { time map { o => Seq("--time") } getOrElse Seq() } + { nameSort map { n => Seq("--name-sort") } getOrElse Seq() } cli(wp.overrides ++ params, expectedExitCode) } @@ -724,9 +724,9 @@ class WskNamespace() def get( namespace: Option[String] = None, expectedExitCode: Int, - time: Option[Boolean] = None)( + nameSort: Option[Boolean] = None)( implicit wp: WskProps): RunResult = { - val params = { time map { t => Seq("--time") } getOrElse Seq() } + val params = { nameSort map { n => Seq("--name-sort") } getOrElse Seq() } cli(wp.overrides ++ Seq(noun, "get", resolve(namespace), "--auth", wp.authKey) ++ params, expectedExitCode) } } @@ -825,7 +825,7 @@ class WskApiExperimental extends RunWskCmd { limit: Option[Int] = None, since: Option[Instant] = None, full: Option[Boolean] = None, - time: Option[Boolean] = None, + nameSort: Option[Boolean] = None, expectedExitCode: Int = SUCCESS_EXIT)( implicit wp: WskProps): RunResult = { val params = Seq(noun, "list", "--auth", wp.authKey) ++ @@ -835,7 +835,7 @@ class WskApiExperimental extends RunWskCmd { { limit map { l => Seq("--limit", l.toString) } getOrElse Seq() } ++ { since map { i => Seq("--since", i.toEpochMilli.toString) } getOrElse Seq() } ++ { full map { r => Seq("--full") } getOrElse Seq() } ++ - { time map { t => Seq("--time") } getOrElse Seq() } + { nameSort map { n => Seq("--name-sort") } getOrElse Seq() } cli(wp.overrides ++ params, expectedExitCode, showCmd = true) } @@ -921,7 +921,7 @@ class WskApi() limit: Option[Int] = None, since: Option[Instant] = None, full: Option[Boolean] = None, - time: Option[Boolean] = None, + nameSort: Option[Boolean] = None, expectedExitCode: Int = SUCCESS_EXIT, cliCfgFile: Option[String] = None)( implicit wp: WskProps): RunResult = { @@ -932,7 +932,7 @@ class WskApi() { limit map { l => Seq("--limit", l.toString) } getOrElse Seq() } ++ { since map { i => Seq("--since", i.toEpochMilli.toString) } getOrElse Seq() } ++ { full map { r => Seq("--full") } getOrElse Seq() } ++ - { time map { o => Seq("--time") } getOrElse Seq() } + { nameSort map { n => Seq("--name-sort") } getOrElse Seq() } cli(wp.overrides ++ params, expectedExitCode, showCmd = true, env = Map("WSK_CONFIG_FILE" -> cliCfgFile.getOrElse(""))) } diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala b/tests/src/test/scala/system/basic/WskBasicTests.scala index 6bf2ab5e3b8..352c5b8a33b 100644 --- a/tests/src/test/scala/system/basic/WskBasicTests.scala +++ b/tests/src/test/scala/system/basic/WskBasicTests.scala @@ -196,7 +196,7 @@ class WskBasicTests pkg.create(name) } } - val original = wsk.pkg.list().stdout + val original = wsk.pkg.list(nameSort = Some(true)).stdout // Create list with package names in correct order val scalaSorted = List(s"${packageName}1", s"${packageName}2", s"${packageName}3") // Filter out everything not previously created @@ -491,7 +491,7 @@ class WskBasicTests action.create(name, defaultAction) } } - val original = wsk.action.list().stdout + val original = wsk.action.list(nameSort = Some(true)).stdout // Create list with action names in correct order val scalaSorted = List(s"${actionName}1", s"${actionName}2", s"${actionName}3") // Filter out everything not previously created @@ -664,7 +664,7 @@ class WskBasicTests trigger.create(name) } } - val original = wsk.trigger.list().stdout + val original = wsk.trigger.list(nameSort = Some(true)).stdout // Create list with trigger names in correct order val scalaSorted = List(s"${triggerName}1", s"${triggerName}2", s"${triggerName}3") // Filter out everything not previously created @@ -849,7 +849,7 @@ class WskBasicTests rule.create(name, trigger = triggerName, action = actionName) } } - val original = wsk.rule.list().stdout + val original = wsk.rule.list(nameSort = Some(true)).stdout // Create list with rule names in correct order val scalaSorted = List(s"${ruleName}1", s"${ruleName}2", s"${ruleName}3") // Filter out everything not previously created diff --git a/tests/src/test/scala/system/basic/WskRuleTests.scala b/tests/src/test/scala/system/basic/WskRuleTests.scala index bddd017050b..9cacc6c9839 100644 --- a/tests/src/test/scala/system/basic/WskRuleTests.scala +++ b/tests/src/test/scala/system/basic/WskRuleTests.scala @@ -384,8 +384,8 @@ class WskRuleTests wsk.rule.disable(ruleName) val listOutput = wsk.rule.list().stdout.lines - listOutput.find(_.contains(ruleName)).get should (include(ruleName) and include("inactive")) listOutput.find(_.contains(ruleName2)).get should (include(ruleName2) and include("active")) + listOutput.find(_.contains(ruleName)).get should (include(ruleName) and include("inactive")) wsk.rule.list().stdout should not include ("Unknown") } diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala index c5c5627eaf5..81f504d0a94 100644 --- a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala +++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala @@ -131,12 +131,12 @@ class ApiGwTests limit: Option[Int] = None, since: Option[Instant] = None, full: Option[Boolean] = None, - time: Option[Boolean] = None, + nameSort: Option[Boolean] = None, expectedExitCode: Int = SUCCESS_EXIT, cliCfgFile: Option[String] = Some(cliWskPropsFile.getCanonicalPath())): RunResult = { checkThrottle() - wsk.api.list(basepathOrApiName, relpath, operation, limit, since, full, time, expectedExitCode, cliCfgFile) + wsk.api.list(basepathOrApiName, relpath, operation, limit, since, full, nameSort, expectedExitCode, cliCfgFile) } def apiGet( @@ -163,6 +163,42 @@ class ApiGwTests behavior of "Wsk api" + it should "list api alphabetically by Base/Rel/Verb" in { + val baseName = "/BaseTestPathApiList" + val actionName = "actionName" + val file = TestUtils.getTestActionFilename(s"echo-web-http.js") + try { + // Create Action for apis + var action = wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true")) + println("action creation: " + action.stdout) + // Create apis + for (i <- 1 to 3) { + val base = s"$baseName$i" + var api = apiCreate( + basepath = Some(base), + relpath = Some("/relPath"), + operation = Some("GET"), + action = Some(actionName)) + println("api creation: " + api.stdout) + } + val original = apiList(nameSort = Some(true)).stdout + val originalFull = apiList(full = Some(true), nameSort = Some(true)).stdout + val scalaSorted = List(s"${baseName}1" + "/", s"${baseName}2" + "/", s"${baseName}3" + "/") + val regex = s"${baseName}[1-3]/".r + val list = (regex.findAllMatchIn(original)).toList + val listFull = (regex.findAllMatchIn(originalFull)).toList + + scalaSorted.toString shouldEqual list.toString + scalaSorted.toString shouldEqual listFull.toString + } finally { + // Clean up Apis + for (i <- 1 to 3) { + val deleteApis = apiDelete(basepathOrApiName = s"${baseName}$i", expectedExitCode = DONTCARE_EXIT) + } + val deleteAction = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT) + } + } + it should "reject an api commands with an invalid path parameter" in { val badpath = "badpath" @@ -907,44 +943,4 @@ class ApiGwTests var deleteresult = apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT) } } - - it should "list api alphabetically by Base/Rel/Verb" in { - val actionName = "actionApiListTest" - val baseName = "/BaseTestPathApiList" - - try { - // Create Actions for apis - val file = TestUtils.getTestActionFilename(s"echo-web-http.js") - for (i <- 1 to 3) { - val name = s"$actionName$i" - wsk.action.create(name = name, artifact = Some(file), web = Some("true"), expectedExitCode = SUCCESS_EXIT) - } - // Create apis - for (i <- 1 to 3) { - val base = s"$baseName$i" - val action = s"$actionName$i" - val api = apiCreate( - basepath = Some(base), - relpath = Some("/relPath"), - operation = Some("GET"), - action = Some(action), - expectedExitCode = SUCCESS_EXIT) - } - val original = apiList().stdout - val originalFull = apiList(full = Some(true)).stdout - val scalaSorted = List(s"${baseName}1" + "/", s"${baseName}2" + "/", s"${baseName}3" + "/") - val regex = s"${baseName}[1-3]/".r - val list = (regex.findAllMatchIn(original)).toList - val listFull = (regex.findAllMatchIn(originalFull)).toList - - scalaSorted.toString shouldEqual list.toString - scalaSorted.toString shouldEqual listFull.toString - } finally { - // Clean up Apis - for (i <- 1 to 3) { - val deleteApis = apiDelete(basepathOrApiName = s"${baseName}$i", expectedExitCode = DONTCARE_EXIT) - val deleteActions = wsk.action.delete(name = s"$actionName$i", expectedExitCode = DONTCARE_EXIT) - } - } - } } diff --git a/tools/cli/go-whisk-cli/commands/action.go b/tools/cli/go-whisk-cli/commands/action.go index 5d32e055f74..46fe2004dfa 100644 --- a/tools/cli/go-whisk-cli/commands/action.go +++ b/tools/cli/go-whisk-cli/commands/action.go @@ -320,8 +320,8 @@ var actionListCmd = &cobra.Command{ return actionListError(qualifiedName.entityName, options, err) } - orderFlag := flags.common.time - printList(actions, orderFlag) + sortByName := flags.common.nameSort + printList(actions, sortByName) return nil }, @@ -937,7 +937,7 @@ func init() { actionListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result")) actionListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection")) - actionListCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) + actionListCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block")) actionCmd.AddCommand( actionCreateCmd, diff --git a/tools/cli/go-whisk-cli/commands/activation.go b/tools/cli/go-whisk-cli/commands/activation.go index e8516b8adee..813188a6b5a 100644 --- a/tools/cli/go-whisk-cli/commands/activation.go +++ b/tools/cli/go-whisk-cli/commands/activation.go @@ -93,7 +93,7 @@ var activationListCmd = &cobra.Command{ if options.Docs == true { printFullActivationList(activations) } else { - printList(activations, true) // Default sorting for Activations are by creation time, hence orderFlag is always true + printList(activations, false) // Default sorting for Activations are by creation time, hence sortByName is always false } return nil diff --git a/tools/cli/go-whisk-cli/commands/api.go b/tools/cli/go-whisk-cli/commands/api.go index a88f3ee4fcc..e9df112a069 100644 --- a/tools/cli/go-whisk-cli/commands/api.go +++ b/tools/cli/go-whisk-cli/commands/api.go @@ -520,7 +520,7 @@ var apiListCmd = &cobra.Command{ retApiArray = (*whisk.RetApiArray)(retApi) } //Checks for any order flags being passed - orderFlag := false // APIs currently do not return in order by creation time, therefore aloways sort Alphabetically + sortByName := flags.common.nameSort // Display the APIs - applying any specified filtering if (flags.common.full) { fmt.Fprintf(color.Output, @@ -529,9 +529,9 @@ var apiListCmd = &cobra.Command{ "ok": color.GreenString("ok:"), })) for i := 0; i < len(retApiArray.Apis); i++ { - orderFilteredList = append(orderFilteredList, genFilteredListV2(retApiArray.Apis[i].ApiValue, apiPath, apiVerb)...) + orderFilteredList = append(orderFilteredList, genFilteredList(retApiArray.Apis[i].ApiValue, apiPath, apiVerb)...) } - printList(orderFilteredList, orderFlag) // Sends an array of structs that contains specifed variables that are not truncated + printList(orderFilteredList, sortByName) // Sends an array of structs that contains specifed variables that are not truncated } else { if (len(retApiArray.Apis) > 0) { // Dynamically create the output format string based on the maximum size of the @@ -545,16 +545,16 @@ var apiListCmd = &cobra.Command{ "ok": color.GreenString("ok:"), })) for i := 0; i < len(retApiArray.Apis); i++ { - orderFilteredRow = append(orderFilteredRow, genFilteredRowV2(retApiArray.Apis[i].ApiValue, apiPath, apiVerb, maxActionNameSize, maxApiNameSize)...) + orderFilteredRow = append(orderFilteredRow, genFilteredRow(retApiArray.Apis[i].ApiValue, apiPath, apiVerb, maxActionNameSize, maxApiNameSize)...) } - printList(orderFilteredRow, orderFlag) // Sends an array of structs that contains specifed variables that are truncated + printList(orderFilteredRow, sortByName) // Sends an array of structs that contains specifed variables that are truncated } else { fmt.Fprintf(color.Output, wski18n.T("{{.ok}} APIs\n", map[string]interface{}{ "ok": color.GreenString("ok:"), })) - printList(orderFilteredRow, orderFlag) // Sends empty orderFilteredRow so that defaultHeader can be printed + printList(orderFilteredRow, sortByName) // Sends empty orderFilteredRow so that defaultHeader can be printed } } @@ -566,7 +566,7 @@ var apiListCmd = &cobra.Command{ // ApiFilteredLists for the purpose of ordering and printing in a list form. // NOTE: genFilteredRow() generates entries with one line per configuration // property (action name, verb, api name, api gw url) -func genFilteredListV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string) []whisk.ApiFilteredList{ +func genFilteredList(resultApi *whisk.RetApi, apiPath string, apiVerb string) []whisk.ApiFilteredList{ var orderInfo whisk.ApiFilteredList var orderInfoArr []whisk.ApiFilteredList baseUrl := strings.TrimSuffix(resultApi.BaseUrl, "/") @@ -574,13 +574,13 @@ func genFilteredListV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string basePath := resultApi.Swagger.BasePath if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) { for path, _ := range resultApi.Swagger.Paths { - whisk.Debug(whisk.DbgInfo, "genFilteredListV2: comparing api relpath: %s\n", path) + whisk.Debug(whisk.DbgInfo, "genFilteredList: comparing api relpath: %s\n", path) if ( len(apiPath) == 0 || path == apiPath) { - whisk.Debug(whisk.DbgInfo, "genFilteredListV2: relpath matches\n") + whisk.Debug(whisk.DbgInfo, "genFilteredList: relpath matches\n") for op, opv := range resultApi.Swagger.Paths[path] { - whisk.Debug(whisk.DbgInfo, "genFilteredListV2: comparing operation: '%s'\n", op) + whisk.Debug(whisk.DbgInfo, "genFilteredList: comparing operation: '%s'\n", op) if ( len(apiVerb) == 0 || strings.ToLower(op) == strings.ToLower(apiVerb)) { - whisk.Debug(whisk.DbgInfo, "genFilteredListV2: operation matches: %#v\n", opv) + whisk.Debug(whisk.DbgInfo, "genFilteredList: operation matches: %#v\n", opv) var actionName string if (opv.XOpenWhisk == nil) { actionName = "" @@ -600,11 +600,11 @@ func genFilteredListV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string return orderInfoArr } -// genFilteredRowV2(resultApi, api, maxApiNameSize, maxApiNameSize) generates an array of +// genFilteredRow(resultApi, api, maxApiNameSize, maxApiNameSize) generates an array of // ApiFilteredRows for the purpose of ordering and printing in a list form by parsing and // initializing vaules for each individual ApiFilteredRow struct. // NOTE: Large action and api name values will be truncated by their associated max size parameters. -func genFilteredRowV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string, maxActionNameSize int, maxApiNameSize int) []whisk.ApiFilteredRow { +func genFilteredRow(resultApi *whisk.RetApi, apiPath string, apiVerb string, maxActionNameSize int, maxApiNameSize int) []whisk.ApiFilteredRow { var orderInfo whisk.ApiFilteredRow var orderInfoArr []whisk.ApiFilteredRow baseUrl := strings.TrimSuffix(resultApi.BaseUrl, "/") @@ -612,13 +612,13 @@ func genFilteredRowV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string, basePath := resultApi.Swagger.BasePath if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) { for path, _ := range resultApi.Swagger.Paths { - whisk.Debug(whisk.DbgInfo, "genFilteredRowV2: comparing api relpath: %s\n", path) + whisk.Debug(whisk.DbgInfo, "genFilteredRow: comparing api relpath: %s\n", path) if ( len(apiPath) == 0 || path == apiPath) { - whisk.Debug(whisk.DbgInfo, "genFilteredRowV2: relpath matches\n") + whisk.Debug(whisk.DbgInfo, "genFilteredRow: relpath matches\n") for op, opv := range resultApi.Swagger.Paths[path] { - whisk.Debug(whisk.DbgInfo, "genFilteredRowV2: comparing operation: '%s'\n", op) + whisk.Debug(whisk.DbgInfo, "genFilteredRow: comparing operation: '%s'\n", op) if ( len(apiVerb) == 0 || strings.ToLower(op) == strings.ToLower(apiVerb)) { - whisk.Debug(whisk.DbgInfo, "genFilteredRowV2: operation matches: %#v\n", opv) + whisk.Debug(whisk.DbgInfo, "genFilteredRow: operation matches: %#v\n", opv) var actionName string if (opv.XOpenWhisk == nil) { actionName = "" @@ -952,7 +952,7 @@ func init() { apiGetCmd.Flags().StringVarP(&flags.common.format, "format", "", formatOptionJson, wski18n.T("Specify the API output `TYPE`, either json or yaml")) apiListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result")) apiListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection")) - apiListCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) + apiListCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by order of [BASE_PATH | API_NAME], API_PATH, then API_VERB; only applicable within the limit/skip returned entity block")) apiListCmd.Flags().BoolVarP(&flags.common.full, "full", "f", false, wski18n.T("display full description of each API")) apiCmd.AddCommand( apiCreateCmd, diff --git a/tools/cli/go-whisk-cli/commands/flags.go b/tools/cli/go-whisk-cli/commands/flags.go index 11c46d665f3..15f9ed46c00 100644 --- a/tools/cli/go-whisk-cli/commands/flags.go +++ b/tools/cli/go-whisk-cli/commands/flags.go @@ -61,7 +61,7 @@ type Flags struct { feed string // name of feed detail bool format string - time bool // orders list by creation time + nameSort bool // sorts list alphabetically by entity name } property struct { diff --git a/tools/cli/go-whisk-cli/commands/namespace.go b/tools/cli/go-whisk-cli/commands/namespace.go index 9e972448ab5..8c4031993d6 100644 --- a/tools/cli/go-whisk-cli/commands/namespace.go +++ b/tools/cli/go-whisk-cli/commands/namespace.go @@ -55,7 +55,7 @@ var namespaceListCmd = &cobra.Command{ werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXITCODE_ERR_NETWORK, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) return werr } - printList(namespaces, false) // `--order` flag appliest to `namespace get`, not list, so must pass value false for printList here + printList(namespaces, false) // `-t` flag appliest to `namespace get`, not list, so must pass value false for printList here return nil }, } @@ -99,18 +99,18 @@ var namespaceGetCmd = &cobra.Command{ fmt.Fprintf(color.Output, wski18n.T("Entities in namespace: {{.namespace}}\n", map[string]interface{}{"namespace": boldString(getClientNamespace())})) - orderFlag := flags.common.time - printList(namespace.Contents.Packages, orderFlag) - printList(namespace.Contents.Actions, orderFlag) - printList(namespace.Contents.Triggers, orderFlag) - printList(namespace.Contents.Rules, orderFlag) + sortByName := flags.common.nameSort + printList(namespace.Contents.Packages, sortByName) + printList(namespace.Contents.Actions, sortByName) + printList(namespace.Contents.Triggers, sortByName) + printList(namespace.Contents.Rules, sortByName) return nil }, } func init() { - namespaceGetCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) + namespaceGetCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block")) namespaceCmd.AddCommand( namespaceListCmd, diff --git a/tools/cli/go-whisk-cli/commands/package.go b/tools/cli/go-whisk-cli/commands/package.go index 78fdd155802..68750970afd 100644 --- a/tools/cli/go-whisk-cli/commands/package.go +++ b/tools/cli/go-whisk-cli/commands/package.go @@ -411,8 +411,8 @@ var packageListCmd = &cobra.Command{ return werr } - orderFlag := flags.common.time - printList(packages, orderFlag) + sortByName := flags.common.nameSort + printList(packages, sortByName) return nil }, @@ -524,7 +524,7 @@ func init() { packageListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of packages from the result")) packageListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of packages from the collection")) - packageListCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) + packageListCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block")) packageCmd.AddCommand( packageBindCmd, diff --git a/tools/cli/go-whisk-cli/commands/rule.go b/tools/cli/go-whisk-cli/commands/rule.go index 5a22a9618dc..256dca24252 100644 --- a/tools/cli/go-whisk-cli/commands/rule.go +++ b/tools/cli/go-whisk-cli/commands/rule.go @@ -403,8 +403,8 @@ var ruleListCmd = &cobra.Command{ } } - orderFlag := flags.common.time - printList(rules, orderFlag) + sortByName := flags.common.nameSort + printList(rules, sortByName) return nil }, } @@ -416,7 +416,7 @@ func init() { ruleListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of rules from the result")) ruleListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of rules from the collection")) - ruleListCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) + ruleListCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block")) ruleCmd.AddCommand( ruleCreateCmd, diff --git a/tools/cli/go-whisk-cli/commands/trigger.go b/tools/cli/go-whisk-cli/commands/trigger.go index dfc7dbb70c4..4ed9bb47b7a 100644 --- a/tools/cli/go-whisk-cli/commands/trigger.go +++ b/tools/cli/go-whisk-cli/commands/trigger.go @@ -457,8 +457,8 @@ var triggerListCmd = &cobra.Command{ werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXITCODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) return werr } - orderFlag := flags.common.time - printList(triggers, orderFlag) + sortByName := flags.common.nameSort + printList(triggers, sortByName) return nil }, } @@ -511,7 +511,7 @@ func init() { triggerListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of triggers from the result")) triggerListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of triggers from the collection")) - triggerListCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) + triggerListCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block")) triggerCmd.AddCommand( triggerFireCmd, diff --git a/tools/cli/go-whisk-cli/commands/util.go b/tools/cli/go-whisk-cli/commands/util.go index 8bcbc5c302f..11e02fedd72 100644 --- a/tools/cli/go-whisk-cli/commands/util.go +++ b/tools/cli/go-whisk-cli/commands/util.go @@ -249,24 +249,24 @@ func isValidJSON(value string) (bool) { var boldString = color.New(color.Bold).SprintFunc() -type Orderables []whisk.Orderable +type Sortables []whisk.Sortable // Uses quickSort to sort commands based on their compare methods -// Param: Takes in a array of Orderable interfaces which contains a specific command -func Swap(orderables Orderables, i, j int) { orderables[i], orderables[j] = orderables[j], orderables[i] } +// Param: Takes in a array of Sortable interfaces which contains a specific command +func Swap(sortables Sortables, i, j int) { sortables[i], sortables[j] = sortables[j], sortables[i] } -func toPrintable(orderable []whisk.Orderable) []whisk.Printable{ - sortedPrintable := make([]whisk.Printable, len(orderable), len(orderable)) - for i := range orderable { - sortedPrintable[i] = orderable[i].(whisk.Printable) +func toPrintable(sortable []whisk.Sortable) []whisk.Printable{ + sortedPrintable := make([]whisk.Printable, len(sortable), len(sortable)) + for i := range sortable { + sortedPrintable[i] = sortable[i].(whisk.Printable) } return sortedPrintable } // Prints the parameters/list for wsk xxxx list -// Identifies type and then copies array into an array of interfaces(Orderable) to be sorted and printed +// Identifies type and then copies array into an array of interfaces(Sortable) to be sorted and printed // Param: Takes in an interace which contains an array of a command(Ex: []Action) -func printList(collection interface{}, orderFlag bool) { - var commandToSort []whisk.Orderable +func printList(collection interface{}, sortByName bool) { + var commandToSort []whisk.Sortable switch collection := collection.(type){ case []whisk.Action: for i := range collection { @@ -301,28 +301,28 @@ func printList(collection interface{}, orderFlag bool) { commandToSort = append(commandToSort, collection[i]) } } - if !orderFlag && len(commandToSort) > 0 { - quickSort(commandToSort, 0, len(commandToSort)-1, orderFlag) + if sortByName && len(commandToSort) > 0 { + quickSort(commandToSort, 0, len(commandToSort)-1) } printCommandsList(toPrintable(commandToSort), makeDefaultHeader(collection)) } -func quickSort(array Orderables, left int, right int, flag bool) { +func quickSort(toSort Sortables, left int, right int) { low := left high := right - pivot := array[(left + right) / 2] + pivot := toSort[(left + right) / 2] for low <= high { - for array[low].Compare(pivot, flag) { low++ } - for pivot.Compare(array[high], flag) { high-- } + for toSort[low].Compare(pivot) { low++ } + for pivot.Compare(toSort[high]) { high-- } if low <= high { - Swap(array, low, high) + Swap(toSort, low, high) low++ high-- } } - if left < high { quickSort(array, left, high, flag) } - if low < right { quickSort(array, low, right, flag) } + if left < high { quickSort(toSort, left, high) } + if low < right { quickSort(toSort, low, right) } } // makeDefaultHeader(collection) returns the default header to be used in case diff --git a/tools/cli/go-whisk-cli/commands/wsk.go b/tools/cli/go-whisk-cli/commands/wsk.go index f9c6f6418dd..8d520e9bb7c 100644 --- a/tools/cli/go-whisk-cli/commands/wsk.go +++ b/tools/cli/go-whisk-cli/commands/wsk.go @@ -44,7 +44,7 @@ func init() { WskCmd.SetHelpTemplate(`{{with or .Long .Short }}{{.}} {{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`) -listCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest")) +listCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block")) WskCmd.AddCommand( actionCmd, diff --git a/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json b/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json index 99790e9ff83..9155981a87f 100644 --- a/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json +++ b/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json @@ -1516,6 +1516,10 @@ "translation": "prints bash command completion script to stdout" }, { - "id": "sorts a list by creation time, from newest to oldest", - "translation": "sorts a list by creation time, from newest to oldest" + "id": "sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block", + "translation": "sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block" + }, + { + "id": "sorts a list alphabetically by order of [BASE_PATH | API_NAME], API_PATH, then API_VERB; only applicable within the limit/skip returned entity block", + "translation": "sorts a list alphabetically by order of [BASE_PATH | API_NAME], API_PATH, then API_VERB; only applicable within the limit/skip returned entity block" }] diff --git a/tools/cli/go-whisk/whisk/action.go b/tools/cli/go-whisk/whisk/action.go index 4a22016c406..119175f4fac 100644 --- a/tools/cli/go-whisk/whisk/action.go +++ b/tools/cli/go-whisk/whisk/action.go @@ -60,31 +60,28 @@ type ActionListOptions struct { Docs bool `url:"docs,omitempty"` } -// Compare(orderable, orderFlag) compares action to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(action Action) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - var actionString string - var compareString string - actionToCompare := orderable.(Action) - - actionString = strings.ToLower(fmt.Sprintf("%s%s", action.Namespace, action.Name)) - compareString = strings.ToLower(fmt.Sprintf("%s%s", actionToCompare.Namespace, - actionToCompare.Name)) - - //return actionString < compareString - if strings.Contains(action.Namespace, "/") && !strings.Contains(actionToCompare.Namespace, "/") { - return false - } else if !strings.Contains(action.Namespace, "/") && strings.Contains(actionToCompare.Namespace, "/") { - return true - } else if strings.Contains(action.Namespace, "/") && strings.Contains(actionToCompare.Namespace, "/") { - return actionString < compareString - } else { - return action.Name < actionToCompare.Name - } +// Compare(sortable) compares action to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type Action. +// ***Method of type Sortable*** +func(action Action) Compare(sortable Sortable) (bool) { + // Sorts alphabetically by NAMESPACE -> PACKAGE_NAME -> ACTION_NAME, with + // actions under default package at the top. + var actionString string + var compareString string + actionToCompare := sortable.(Action) + + actionString = strings.ToLower(fmt.Sprintf("%s%s", action.Namespace, action.Name)) + compareString = strings.ToLower(fmt.Sprintf("%s%s", actionToCompare.Namespace, + actionToCompare.Name)) + if strings.Contains(action.Namespace, "/") && !strings.Contains(actionToCompare.Namespace, "/") { + return false + } else if !strings.Contains(action.Namespace, "/") && strings.Contains(actionToCompare.Namespace, "/") { + return true + } else if strings.Contains(action.Namespace, "/") && strings.Contains(actionToCompare.Namespace, "/") { + return actionString < compareString + } else { + return action.Name < actionToCompare.Name + } } // ToHeaderString() returns the header for a list of actions @@ -96,7 +93,7 @@ func(action Action) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk action list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(action Action) ToSummaryRowString() string{ var kind string publishState := wski18n.T("private") diff --git a/tools/cli/go-whisk/whisk/activation.go b/tools/cli/go-whisk/whisk/activation.go index 4e81531a21c..33fca4d1ee3 100644 --- a/tools/cli/go-whisk/whisk/activation.go +++ b/tools/cli/go-whisk/whisk/activation.go @@ -71,11 +71,11 @@ type Log struct { Time string `json:"time,omitempty"` } -// Compare(orderable) compares activation to orderable for the purpose of sorting. -// params: orderable that is also of type Activation (REQUIRED). -// ***Method of type Orderable*** +// Compare(sortable) compares activation to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type Activation. +// ***Method of type Sortable*** // ***Currently, no method of sorting defined*** -func(activation Activation) Compare(orderable Orderable, orderFlag bool) (bool) { +func(activation Activation) Compare(sortable Sortable) (bool) { return true } @@ -87,7 +87,7 @@ func(activation Activation) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk activation list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(activation Activation) ToSummaryRowString() string { return fmt.Sprintf("%s %-20s\n", activation.ActivationID, activation.Name) } diff --git a/tools/cli/go-whisk/whisk/api.go b/tools/cli/go-whisk/whisk/api.go index 148ae091434..e9a9d113b6b 100644 --- a/tools/cli/go-whisk/whisk/api.go +++ b/tools/cli/go-whisk/whisk/api.go @@ -185,24 +185,21 @@ const ( // Api Methods // ///////////////// -// Compare(orderable, orderFlag) compares api to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(api ApiFilteredList) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - apiToCompare := orderable.(ApiFilteredList) - var apiString string - var compareString string - - // Check for orderFlag to build proper comparison strings - apiString = strings.ToLower(fmt.Sprintf("%s%s%s",api.BasePath, api.RelPath, - api.Verb)) - compareString = strings.ToLower(fmt.Sprintf("%s%s%s", apiToCompare.BasePath, - apiToCompare.RelPath, apiToCompare.Verb)) - - return apiString < compareString +// Compare(sortable) compares api to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type ApiFilteredList. +// ***Method of type Sortable*** +func(api ApiFilteredList) Compare(sortable Sortable) (bool) { + // Sorts alphabetically by [BASE_PATH | API_NAME] -> REL_PATH -> API_VERB + apiToCompare := sortable.(ApiFilteredList) + var apiString string + var compareString string + + apiString = strings.ToLower(fmt.Sprintf("%s%s%s",api.BasePath, api.RelPath, + api.Verb)) + compareString = strings.ToLower(fmt.Sprintf("%s%s%s", apiToCompare.BasePath, + apiToCompare.RelPath, apiToCompare.Verb)) + + return apiString < compareString } // ToHeaderString() returns the header for a list of apis @@ -212,7 +209,7 @@ func(api ApiFilteredList) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk api list` or `wsk api-experimental list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(api ApiFilteredList) ToSummaryRowString() string { return fmt.Sprintf("%s %s %s %s %s %s", fmt.Sprintf("%s: %s\n", wski18n.T("Action"), api.ActionName), @@ -223,24 +220,21 @@ func(api ApiFilteredList) ToSummaryRowString() string { fmt.Sprintf(" %s: %s\n", wski18n.T("URL"), api.Url)) } -// Compare(orderable, orderFlag) compares api to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(api ApiFilteredRow) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - var apiString string - var compareString string - apiToCompare := orderable.(ApiFilteredRow) +// Compare(sortable) compares api to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type ApiFilteredRow. +// ***Method of type Sortable*** +func(api ApiFilteredRow) Compare(sortable Sortable) (bool) { + // Sorts alphabetically by [BASE_PATH | API_NAME] -> REL_PATH -> API_VERB + var apiString string + var compareString string + apiToCompare := sortable.(ApiFilteredRow) - // Check for orderFlag to build proper comparison strings - apiString = strings.ToLower(fmt.Sprintf("%s%s%s",api.BasePath, api.RelPath, - api.Verb)) - compareString = strings.ToLower(fmt.Sprintf("%s%s%s", apiToCompare.BasePath, - apiToCompare.RelPath, apiToCompare.Verb)) + apiString = strings.ToLower(fmt.Sprintf("%s%s%s",api.BasePath, api.RelPath, + api.Verb)) + compareString = strings.ToLower(fmt.Sprintf("%s%s%s", apiToCompare.BasePath, + apiToCompare.RelPath, apiToCompare.Verb)) - return apiString < compareString + return apiString < compareString } // ToHeaderString() returns the header for a list of apis @@ -250,7 +244,7 @@ func(api ApiFilteredRow) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk api list -f` or `wsk api-experimental list -f`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(api ApiFilteredRow) ToSummaryRowString() string { return fmt.Sprintf(api.FmtString, api.ActionName, api.Verb, api.ApiName, api.Url) } @@ -407,7 +401,7 @@ func (s *ApiService) Delete(api *ApiDeleteRequest, options *ApiDeleteRequestOpti } -func validateApiListResponse(apiList *ApiListResponseV2) error { +func validateApiListResponse(apiList *ApiListResponse) error { for i := 0; i < len(apiList.Apis); i++ { if apiList.Apis[i].ApiValue == nil { Debug(DbgError, "validateApiResponse: No value stanza in api %v\n", apiList.Apis[i]) diff --git a/tools/cli/go-whisk/whisk/namespace.go b/tools/cli/go-whisk/whisk/namespace.go index 8d7448a197b..6d55468b735 100644 --- a/tools/cli/go-whisk/whisk/namespace.go +++ b/tools/cli/go-whisk/whisk/namespace.go @@ -42,14 +42,12 @@ type NamespaceService struct { client *Client } -// Compare(orderable, orderFlag) compares namespace to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(namespace Namespace) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - namespaceToCompare := orderable.(Namespace) +// Compare(sortable) compares namespace to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type Namespace. +// ***Method of type Sortable*** +func(namespace Namespace) Compare(sortable Sortable) (bool) { + // Sorts alphabetically + namespaceToCompare := sortable.(Namespace) var namespaceString string var compareString string @@ -68,7 +66,7 @@ func(namespace Namespace) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk namespace list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(namespace Namespace) ToSummaryRowString() string { return fmt.Sprintf("%s\n", namespace.Name) } diff --git a/tools/cli/go-whisk/whisk/package.go b/tools/cli/go-whisk/whisk/package.go index c15ee77de26..ce91835b6e7 100644 --- a/tools/cli/go-whisk/whisk/package.go +++ b/tools/cli/go-whisk/whisk/package.go @@ -87,24 +87,22 @@ type PackageListOptions struct { Docs bool `url:"docs,omitempty"` } -// Compare(orderable, orderFlag) compares xPackage to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(xPackage Package) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - packageToCompare := orderable.(Package) +// Compare(sortable) compares xPackage to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type Package. +// ***Method of type Sortable*** +func(xPackage Package) Compare(sortable Sortable) (bool) { + // Sorts alphabetically by NAMESPACE -> PACKAGE_NAME + packageToCompare := sortable.(Package) - var packageString string - var compareString string + var packageString string + var compareString string - packageString = strings.ToLower(fmt.Sprintf("%s%s",xPackage.Namespace, - xPackage.Name)) - compareString = strings.ToLower(fmt.Sprintf("%s%s", packageToCompare.Namespace, - packageToCompare.Name)) + packageString = strings.ToLower(fmt.Sprintf("%s%s",xPackage.Namespace, + xPackage.Name)) + compareString = strings.ToLower(fmt.Sprintf("%s%s", packageToCompare.Namespace, + packageToCompare.Name)) - return packageString < compareString + return packageString < compareString } // ToHeaderString() returns the header for a list of actions @@ -115,7 +113,7 @@ func(pkg Package) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk package list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(xPackage Package) ToSummaryRowString() string{ publishState := wski18n.T("private") diff --git a/tools/cli/go-whisk/whisk/rule.go b/tools/cli/go-whisk/whisk/rule.go index 007c99dddd0..f17b91f2562 100644 --- a/tools/cli/go-whisk/whisk/rule.go +++ b/tools/cli/go-whisk/whisk/rule.go @@ -47,22 +47,20 @@ type RuleListOptions struct { Docs bool `url:"docs,omitempty"` } -// Compare(orderable, orderFlag) compares rule to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(rule Rule) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - ruleToCompare := orderable.(Rule) - var ruleString string - var compareString string - - ruleString = strings.ToLower(fmt.Sprintf("%s%s",rule.Namespace, rule.Name)) - compareString = strings.ToLower(fmt.Sprintf("%s%s", ruleToCompare.Namespace, - ruleToCompare.Name)) - - return ruleString < compareString +// Compare(sortable) compares rule to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type Rule. +// ***Method of type Sortable*** +func(rule Rule) Compare(sortable Sortable) (bool) { + // Sorts alphabetically by NAMESPACE -> PACKAGE_NAME + ruleToCompare := sortable.(Rule) + var ruleString string + var compareString string + + ruleString = strings.ToLower(fmt.Sprintf("%s%s",rule.Namespace, rule.Name)) + compareString = strings.ToLower(fmt.Sprintf("%s%s", ruleToCompare.Namespace, + ruleToCompare.Name)) + + return ruleString < compareString } // ToHeaderString() returns the header for a list of rules @@ -74,7 +72,7 @@ func(rule Rule) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk rule list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(rule Rule) ToSummaryRowString() string{ publishState := wski18n.T("private") diff --git a/tools/cli/go-whisk/whisk/trigger.go b/tools/cli/go-whisk/whisk/trigger.go index e800ae1c497..19110f97145 100644 --- a/tools/cli/go-whisk/whisk/trigger.go +++ b/tools/cli/go-whisk/whisk/trigger.go @@ -48,14 +48,12 @@ type TriggerListOptions struct { Docs bool `url:"docs,omitempty"` } -// Compare(orderable, orderFlag) compares trigger to orderable for the purpose of sorting. -// params: orderable that is also of type Action (REQUIRED). -// orderFlag changes sorting algorithm, if other ways to sort are available -// ***Method of type Orderable*** -// ***By default, sorts Alphabetically*** -func(trigger Trigger) Compare(orderable Orderable, orderFlag bool) (bool) { - // convert orderable back to proper type - triggerToCompare := orderable.(Trigger) +// Compare(sortable) compares trigger to sortable for the purpose of sorting. +// REQUIRED: sortable must also be of type Trigger. +// ***Method of type Sortable*** +func(trigger Trigger) Compare(sortable Sortable) (bool) { + // Sorts alphabetically by NAMESPACE -> TRIGGER_NAME + triggerToCompare := sortable.(Trigger) var triggerString string var compareString string @@ -76,7 +74,7 @@ func(trigger Trigger) ToHeaderString() string { // ToSummaryRowString() returns a compound string of required parameters for printing // from CLI command `wsk trigger list`. -// ***Method of type Orderable*** +// ***Method of type Sortable*** func(trigger Trigger) ToSummaryRowString() string { publishState := wski18n.T("private") diff --git a/tools/cli/go-whisk/whisk/util.go b/tools/cli/go-whisk/whisk/util.go index a00b893731b..b1c3500d05b 100644 --- a/tools/cli/go-whisk/whisk/util.go +++ b/tools/cli/go-whisk/whisk/util.go @@ -29,13 +29,13 @@ import ( "../wski18n" ) -// Orderable items are anything that needs to be sorted for listing purposes. -type Orderable interface { - // Compare(orderable, orderFlag) compares an two orderables and returns true +// Sortable items are anything that needs to be sorted for listing purposes. +type Sortable interface { + // Compare(sortable) compares an two sortables and returns true // if the item calling the Compare method is less than toBeCompared. // Sorts alphabetically by default, can have other parameters to sort by - // passed by orderFlag. - Compare(toBeCompared Orderable, orderFlag bool) (bool) + // passed by sortByName. + Compare(toBeCompared Sortable) (bool) } // Printable items are anything that need to be printed for listing purposes.