in openapi/library.go [78:133]
func (a *Library) PrintProductUsage(productCode string, withApi bool) error {
product, ok := a.GetProduct(productCode)
if !ok {
return &InvalidProductError{Code: productCode, library: a}
}
if product.ApiStyle == "rpc" {
cli.Printf(a.writer, "\nUsage:\n aliyun %s <ApiName> --parameter1 value1 --parameter2 value2 ...\n", strings.ToLower(product.Code))
} else {
cli.Printf(a.writer, "\nUsage 1:\n aliyun %s [GET|PUT|POST|DELETE] <PathPattern> --body \"...\" \n", strings.ToLower(product.Code))
cli.Printf(a.writer, "\nUsage 2 (For API with NO PARAMS in PathPattern only.):\n aliyun %s <ApiName> --parameter1 value1 --parameter2 value2 ... --body \"...\"\n", strings.ToLower(product.Code))
}
productName, _ := newmeta.GetProductName(i18n.GetLanguage(), product.Code)
cli.Printf(a.writer, "\nProduct: %s (%s)\n", product.Code, productName)
cli.Printf(a.writer, "Version: %s \n", product.Version)
if withApi {
cli.PrintfWithColor(a.writer, cli.ColorOff, "\nAvailable Api List: \n")
maxNameLen := 0
for _, apiName := range product.ApiNames {
if len(apiName) > maxNameLen {
maxNameLen = len(apiName)
}
}
for _, apiName := range product.ApiNames {
if product.ApiStyle == "restful" {
api, _ := a.GetApi(productCode, product.Version, apiName)
ptn := fmt.Sprintf(" %%-%ds : %%s %%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, ptn, apiName, api.Method, api.PathPattern)
} else {
api, _ := newmeta.GetAPI(i18n.GetLanguage(), productCode, apiName)
if api != nil {
apiDetail, _ := newmeta.GetAPIDetail(i18n.GetLanguage(), productCode, apiName)
// use new api metadata
if api.Deprecated {
fmt := fmt.Sprintf(" %%-%ds [Deprecated]%%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
} else if apiDetail.IsAnonymousAPI() {
fmt := fmt.Sprintf(" %%-%ds [Anonymous]%%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
} else {
fmt := fmt.Sprintf(" %%-%ds %%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
}
} else {
cli.PrintfWithColor(a.writer, cli.Green, " %s\n", apiName)
}
}
}
}
cli.Printf(a.writer, "\nRun `aliyun %s <ApiName> --help` to get more information about this API\n", product.GetLowerCode())
return nil
}