2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-04-03 08:21:33 +03:00
|
|
|
package api
|
|
|
|
|
2015-04-03 08:26:34 +03:00
|
|
|
import (
|
2018-07-25 01:49:55 +03:00
|
|
|
"context"
|
2015-04-03 08:26:34 +03:00
|
|
|
"fmt"
|
2022-03-24 20:58:03 +03:00
|
|
|
"net/http"
|
2015-04-03 08:26:34 +03:00
|
|
|
)
|
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
// Help wraps HelpWithContext using context.Background.
|
2015-04-03 08:26:34 +03:00
|
|
|
func (c *Client) Help(path string) (*Help, error) {
|
2022-03-24 00:47:43 +03:00
|
|
|
return c.HelpWithContext(context.Background(), path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// HelpWithContext reads the help information for the given path.
|
|
|
|
func (c *Client) HelpWithContext(ctx context.Context, path string) (*Help, error) {
|
|
|
|
ctx, cancelFunc := c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2022-03-24 20:58:03 +03:00
|
|
|
r := c.NewRequest(http.MethodGet, fmt.Sprintf("/v1/%s", path))
|
2015-04-03 08:42:05 +03:00
|
|
|
r.Params.Add("help", "1")
|
2018-07-25 01:49:55 +03:00
|
|
|
|
2022-03-24 00:47:43 +03:00
|
|
|
resp, err := c.rawRequestWithContext(ctx, r)
|
2015-04-03 08:26:34 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result Help
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type Help struct {
|
2019-06-27 19:56:31 +03:00
|
|
|
Help string `json:"help"`
|
|
|
|
SeeAlso []string `json:"see_also"`
|
|
|
|
OpenAPI map[string]interface{} `json:"openapi"`
|
2015-04-03 08:21:33 +03:00
|
|
|
}
|