Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ var get = &cobra.Command{
})
}

} else if len(args) >= idCount+1 { // Arg is after IDs
if (len(args)-idCount)%2 == 1 { // This is a query param key
if resource.SingularName != args[0] { // If the resource is plural/get-collection
return completion.Complete(completion.Request{
Type: completion.CompleteQueryParam,
Resource: resource,
Verb: completion.GetAll,
})
} else {
return completion.Complete(completion.Request{
Type: completion.CompleteQueryParam,
Resource: resource,
Verb: completion.Get,
})
}
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions external/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
Create = 2
Update = 4
Delete = 8
GetAll = 16
)

type Request struct {
Expand Down Expand Up @@ -110,6 +111,19 @@ func Complete(c Request) ([]string, cobra.ShellCompDirective) {
}
}

if c.Type&CompleteQueryParam > 0 {
if c.Verb&GetAll > 0 {
for _, k := range strings.Split(c.Resource.GetCollectionInfo.QueryParameters, ",") {
results = append(results, k)
}
} else if c.Verb&Get > 0 {
for _, k := range strings.Split(c.Resource.GetEntityInfo.QueryParameters, ",") {
results = append(results, k)
}
}

}

if c.Type&CompleteAlias > 0 {
jsonApiType := c.Resource.JsonApiType
aliasesForJsonApiType := aliases.GetAliasesForJsonApiType(jsonApiType)
Expand Down
3 changes: 3 additions & 0 deletions external/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type CrudEntityInfo struct {

// Content type to send
ContentType string `yaml:"content-type"`

// A list of valid query parameters
QueryParameters string `yaml:"query"`
}

type CrudEntityAttribute struct {
Expand Down
27 changes: 25 additions & 2 deletions external/resources/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ account-members:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/account-management/account-members/get-all-account-members.html"
url: "/v2/account-members"
query: "page[limit],page[offset],filter"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/account-management/account-members/get-an-account-member.html"
url: "/v2/account-members/{account_members}"
Expand All @@ -57,6 +58,7 @@ account-memberships:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/account-management/account-memberships/get-all-account-memberships.html"
url: "/v2/accounts/{accounts}/account-memberships"
query: "page[limit],page[offset],filter"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/account-management/account-memberships/get-an-account-membership.html"
url: "/v2/accounts/{accounts}/account-memberships/{account_memberships}"
Expand All @@ -78,6 +80,7 @@ accounts:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/account-management/accounts/get-all-accounts.html"
url: "/v2/accounts"
query: "page[limit],page[offset],filter"
get-entity:
#TODO this link is wrong, but the actual page doesn't exist.
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/account-management/accounts/index.html"
Expand Down Expand Up @@ -109,6 +112,7 @@ authentication-realms:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/authentication-realms/get-all-authentication-realms.html"
url: "/v2/authentication-realms"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/authentication-realms/get-an-authentication-realm.html"
url: "/v2/authentication-realms/{authentication_realms}"
Expand All @@ -130,9 +134,11 @@ carts:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/associations/get-customer-carts.html"
url: "/v2/carts"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/get-a-cart.html"
url: "/v2/carts/{carts}"
query: "include"
update-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/create-multi-cart.html#put-update-a-cart"
url: "/v2/carts/{carts}"
Expand All @@ -158,6 +164,7 @@ cart-items:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/cart-items/get-cart-items.html"
url: "/v2/carts/{carts}/items"
query: "include"
update-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/cart-items/update-cart-item.html"
url: "/v2/carts/{carts}/items/{cart_items}"
Expand Down Expand Up @@ -282,6 +289,7 @@ customers:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/customers/get-all-customers.html"
url: "/v2/customers"
query: "page[limit],page[offset],filter"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/customers-and-accounts/customers/get-a-customer.html"
url: "/v2/customers/{customers}"
Expand Down Expand Up @@ -364,6 +372,7 @@ files:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/get-all-files.html"
url: "/v2/files"
query: "page[limit],page[offset],filter"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/get-a-file.html"
url: "/v2/files/{files}"
Expand Down Expand Up @@ -419,6 +428,7 @@ integration-jobs:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/integrations/get-integration-logs.html#get-get-jobs-for-an-integration"
url: "/v2/integrations/{integrations}/jobs"
query: "page[limit],page[offset]"
integration-job-log:
singular-name: "integration-job-log"
json-api-type: "integration-job"
Expand Down Expand Up @@ -502,6 +512,7 @@ oidc-profiles:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/oidc-profiles/get-all-oidc-profiles.html"
url: "/v2/authentication-realms/{authentication_realms}/oidc-profiles"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/oidc-profiles/get-an-oidc-profile.html"
url: "/v2/authentication-realms/{authentication_realms}/oidc-profiles/{oidc_profiles}"
Expand Down Expand Up @@ -532,9 +543,11 @@ orders:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/orders/get-all-orders.html"
url: "/v2/orders"
query: "page[limit],page[offset],filter,include"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/orders/get-an-order.html"
url: "/v2/orders/{orders}"
query: "include"
update-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/orders/update-an-order.html"
url: "/v2/orders/{orders}"
Expand Down Expand Up @@ -603,6 +616,7 @@ password-profiles:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/password-profiles/get-all-password-profiles.html"
url: "/v2/authentication-realms/{authentication_realms}/password-profiles"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/password-profiles/get-a-password-profile.html"
url: "/v2/authentication-realms/{authentication_realms}/password-profiles/{password_profiles}"
Expand Down Expand Up @@ -661,7 +675,7 @@ pcm-catalog-releases:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/releases/catalog-release/get-all-releases-of-a-catalog.html"
url: "/pcm/catalogs/{pcm_catalogs}/releases"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/index.html"
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/releases/get-a-release-of-a-catalog.html"
url: "/pcm/catalogs/{pcm_catalogs}/releases/{pcm_catalog_releases}"
delete-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/releases/catalog-release/delete-a-published-catalog.html"
Expand Down Expand Up @@ -741,6 +755,7 @@ pcm-node-children:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/relationships/get-node-children.html"
url: "/pcm/hierarchies/{pcm_hierarchies}/nodes/{pcm_nodes}/children"
query: "page[limit],page[offset]"
pcm-node-products:
singular-name: "pcm-node-product"
json-api-type: "node"
Expand All @@ -750,6 +765,7 @@ pcm-node-products:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/relationships/get-node-products.html"
url: "/pcm/hierarchies/{pcm_hierarchies}/nodes/{pcm_nodes}/products"
query: "page[limit],page[offset]"
#TBD figure out if this should be the same URL
create-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/relationships/create-node-product-relationships.html"
Expand Down Expand Up @@ -824,6 +840,7 @@ pcm-products:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/products/get-all-products.html"
url: "/pcm/products"
query: "include"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/products/get-a-product.html"
url: "/pcm/products/{pcm_products}"
Expand Down Expand Up @@ -866,6 +883,7 @@ pcm-pricebooks:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/index.html"
url: "/pcm/pricebooks"
#TBD figure out if this should be the same URL
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/get-a-pricebook.html"
url: "/pcm/pricebooks/{pcm_pricebooks}"
Expand Down Expand Up @@ -893,6 +911,7 @@ pcm-product-prices:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/prices/get-all-prices-in-a-pricebook.html"
url: "/pcm/pricebooks/{pcm_pricebooks}/prices"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/prices/get-a-products-prices.html"
url: "/pcm/pricebooks/{pcm_pricebooks}/prices/{pcm_product_prices}"
Expand Down Expand Up @@ -922,7 +941,6 @@ pcm-product-prices:
type: INT
currencies.CAD.includes_tax:
type: BOOL

promotion-codes:
singular-name: "promotion_code"
json-api-type: "promotion_codes"
Expand Down Expand Up @@ -958,6 +976,7 @@ promotions:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/promotions/get-promotions.html"
url: "/v2/promotions"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/promotions/get-a-promotion.html"
url: "/v2/promotions/{promotions}"
Expand Down Expand Up @@ -1030,6 +1049,7 @@ user-authentication-infos:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-info/get-all-user-authentication-info.html"
url: "/v2/authentication-realms/{authentication_realms}/user-authentication-info"
query: "page[limit],page[offset],filter"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-info/get-a-user-authentication-info.html"
url: "/v2/authentication-realms/{authentication_realms}/user-authentication-info/{user_authentication_infos}"
Expand All @@ -1056,6 +1076,7 @@ user-authentication-oidc-profile-infos:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-oidc-profile-info/get-all-user-authentication-oidc-profile-info.html"
url: "/v2/authentication-realms/{authentication_realms}/user-authentication-info/{user_authentication_infos}/user-authentication-oidc-profile-info"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-oidc-profile-info/get-a-user-authentication-oidc-profile-info.html"
url: "/v2/authentication-realms/{authentication_realms}/user-authentication-info/{user_authentication_infos}/user-authentication-oidc-profile-info/{user_authentication_oidc_profile_infos}"
Expand Down Expand Up @@ -1084,6 +1105,7 @@ user-authentication-password-profile-infos:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-password-profiles/get-all-user-authentication-password-profile-info.html"
url: "/v2/authentication-realms/{authentication_realms}/user-authentication-info/{user_authentication_infos}/user-authentication-password-profile-info"
query: "page[limit],page[offset]"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-password-profiles/get-a-user-authentication-password-profile.html"
url: "/v2/authentication-realms/{authentication_realms}/user-authentication-info/{user_authentication_infos}/user-authentication-password-profile-info/{user_authentication_password_profile_infos}"
Expand Down Expand Up @@ -1112,6 +1134,7 @@ v2-products:
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/products/get-all-products.html"
url: "/v2/products"
query: "page[limit],page[offset],filter,sort,include"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/products/get-a-product.html"
url: "/v2/products/{v2_products}"
Expand Down
Loading