Skip to content

Commit 1496541

Browse files
authored
Merge pull request #10 from nvima/improve-readme-yaml-attr
update readme and fix error handling
2 parents 28a4f17 + 3129115 commit 1496541

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ gitdiff:
2626
please help me write a descriptive and informative git commit message:
2727
${STDIN}
2828
output: "choices[0].message.content"
29+
statuscode: 200
2930
env:
3031
- "OPENAI_API_KEY"
3132
translate:
@@ -59,6 +60,31 @@ $ git diff --staged | httpcli gitdiff
5960
Added initial implementation of main.go file with necessary package imports and function call to execute CLI command.
6061
```
6162

63+
## YAML Attributes
64+
In your YAML configuration file, the following attributes can be used to define your API requests:
65+
66+
| Attribute | Required/Optional | Description |
67+
|------------|------------------|---------------------------------------------------------------------------------------------------------------------|
68+
| `url` | Required | The URL to which the API request will be sent. |
69+
| `header` | Optional | Headers to be included in the API request. |
70+
| `data` | Optional | The payload to be sent with the API request |
71+
| `statuscode` | Optional | The expected status code for the API response. If a different response code is received, the CLI tool will return an error and not proceed with parsing the response. |
72+
| `output` | Optional | Specifies how the JSON response should be parsed, e.g., "translations[0].text". If omitted, the entire JSON response will be written to stdout without parsing. |
73+
| `env` | Optional | Searches for environment variables in other YAML attributes and replaces them with the corresponding values using this pattern: ${API_KEY}. |
74+
75+
76+
This structure allows you to easily define and customize your API requests within the YAML configuration file.
77+
78+
## CLI Flags
79+
80+
`httpcli` supports various flags to customize its behavior and provide additional functionality. These flags can be passed along with the command to modify the tool's behavior:
81+
82+
- `--config string`: Specify a custom configuration file. By default, the tool uses the `$HOME/.httpcli.yaml` file. You can provide a different file path using this flag (e.g., `httpcli --config=./my-config.yaml`).
83+
- `--debug`: Enable debug mode to display more detailed error messages and logs for troubleshooting purposes.
84+
- `-h, --help`: Display help information for the `httpcli` command, including a list of available flags and usage instructions.
85+
86+
Use these flags in combination with your API request commands to customize the behavior of `httpcli` according to your needs.
87+
6288
## Work in Progress
6389
Please note that httpcli is a work in progress tool and may contain errors or incomplete features.
6490
However, suggestions and merge requests are always welcome to help improve the tool.

util/handleError.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ func HandleError(cmd *cobra.Command, err error, tplError error) error {
1111
if debug {
1212
fmt.Printf("Debug: %v\n", err)
1313
}
14+
fmt.Println(tplError.Error())
1415
return tplError
1516
}

0 commit comments

Comments
 (0)