-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More cli support #18
Open
outscale-mgo
wants to merge
17
commits into
master
Choose a base branch
from
more-cli-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
More cli support #18
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
87be9ff
document bin
outscale-mgo 707c7a4
document helpers.sh
outscale-mgo 10e43ed
add an option to funclist to generate function from paths
outscale-mgo 58544bb
remove argument-list.json
outscale-mgo cc8fb51
add debug function
outscale-mgo 6835e97
add some debug
outscale-mgo c5ad6ad
enable to choose prefix for Function
outscale-mgo 688508d
funclist now support costum function suffix
outscale-mgo fccf1a3
Document --function-suffix=suffix
outscale-mgo 60f69f2
path is on thw way
outscale-mgo fd88408
add more helper functions
outscale-mgo b885d26
add more helper to handle path type
outscale-mgo 1388426
descripttion for path mode
outscale-mgo 8aafd0f
remove debug
outscale-mgo 45baa79
fix name for path calls
outscale-mgo b408b7e
somewhat generate arguments corectly with path
outscale-mgo 758e70c
fix header, and handle query maybe
outscale-mgo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,11 @@ The language argument is crucial as certain keywords might be interpreted differ | |
The script uses a file called osc-api.json, which represents the OpenAPI specification in JSON format. | ||
For the Outscale API, the YAML source is converted to JSON using yq. | ||
|
||
When generating API calls, COGNAC assumes that the OpenAPI file contains components named CallRequest. | ||
When generating API calls, COGNAC by default assumes that the OpenAPI file contains components named CallRequest. | ||
For example, if the API has a call named `CreatePony`, the corresponding component should be located at `#/components/schemas/CreatePonyRequest`. | ||
|
||
You can change the suffix of functions using `./configure --function-suffix FUNCTION_SUFFIX` | ||
|
||
*Note: There are two versions of yq: one written in Python and one in Go. The default version depends on your distribution. On Arch-based distributions, the Python version is typically the default, whereas on Debian-based distributions, the Go version is default. COGNAC supports both, but to use the Go version, you need to pass `--yq-go` to `./configure`.* | ||
|
||
### Example: Generating a CLI for a New API | ||
|
@@ -44,22 +46,28 @@ To configure the Makefile to generate the CLI with the name `pony-cli`, and adju | |
|
||
Run the following command: | ||
```bash | ||
./configure --cli-name=pony-cli --api-script='curl -s https://ponyapi.yolo | yq $(YQ_ARG) | sed "s/Input/Request/" > osc-api.json' | ||
./configure --cli-name=pony-cli --function-suffix Input --api-script='curl -s https://ponyapi.yolo | yq $(YQ_ARG)" > osc-api.json' | ||
``` | ||
|
||
`-cli-name=pony-cli` set the generated binary name to `pony-cli` | ||
|
||
```bash | ||
--api-script='curl -s https://ponyapi.yolo | yq $(YQ_ARG) | sed "s/Input/Request/" > osc-api.json' | ||
--function-suffix Input | ||
``` | ||
Look for Function named XInput instead of XRequest. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Search for the function named |
||
|
||
```bash | ||
--api-script='curl -s https://ponyapi.yolo | yq $(YQ_ARG) > osc-api.json' | ||
``` | ||
|
||
|
||
This script is used to fetch the API file. | ||
|
||
|
||
Here’s what the script does: | ||
|
||
1. Retrieves the API in YAML format using curl -s `https://ponyapi.yolo/.` | ||
2. Converts the YAML to JSON using yq `$(YQ_ARG)`. *Note the usage of `$(YQ_ARG)`, so ./configure can handle go version of yq* | ||
3. Renames all components named `XInput` to `XRequest`. | ||
|
||
Once this setup is complete, you can now use the Makefile. It's also a good idea to run ./configure --help, as it contains several useful options. | ||
- `--wget-json-search`: Helps with downloading `json-search`, which can be tricky to install, **If unsure, we recommend using this by default** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# funclist | ||
|
||
usage: | ||
``` | ||
./funclist api.json | ||
``` | ||
|
||
Look in an OpenAPI JSON file for the list of functions. To do this, identify which objects in components.schemas end with 'Request'. Each function call is separated by a space. | ||
|
||
# line_check | ||
|
||
usage: | ||
``` | ||
./line_check "test_keywork" "this_arg" <<< "there is this_arg in this line" | ||
``` | ||
|
||
Will return "this_arg". | ||
|
||
This utility was created to avoid calling grep for each keyword we need to check. With this utility, we can pass all our keywords to line_check and then switch based on which keyword was found. | ||
|
||
This is also much faster than multiple calls to grep. | ||
|
||
# osc-api-seems-valid.sh | ||
|
||
This utility is used to check if osc-api.json has been generated correctly. It verifies that the file is a valid JSON and contains at least one API function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,75 @@ | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "json.h" | ||
|
||
int main(int ac, char **av) | ||
{ | ||
struct json_object *j_file = json_object_from_file(av[1]); | ||
bool funclist_from_path = 0; | ||
struct json_object *j_file = NULL; | ||
|
||
struct json_object *compo; | ||
struct json_object *schema; | ||
char *suffix = "Request"; | ||
int ret = 0; | ||
ret = json_object_object_get_ex(j_file, "components", &compo); | ||
if (!ret) | ||
return 1; | ||
json_object_object_get_ex(compo, "schemas", &schema); | ||
if (!ret) | ||
return 1; | ||
int func_ret = 1; | ||
int first = 1; | ||
int i; | ||
|
||
json_object_object_foreach(schema, k, v_) { | ||
char *new_k = strdup(k); | ||
char *resquest = strstr(new_k, "Request"); | ||
if (resquest) { | ||
for (i = 1; i < ac; ++i) { | ||
if (!strcmp(av[i], "--func-suffix")) { | ||
++i; | ||
if (i == ac) { | ||
printf("usage: %s --func-suffix SUFFIX", av[0]); | ||
return 1; | ||
} | ||
suffix = av[i]; | ||
} else if (!j_file) { | ||
j_file = json_object_from_file(av[1]); | ||
} else { | ||
funclist_from_path = 1; | ||
} | ||
} | ||
|
||
if (!funclist_from_path) { | ||
struct json_object *compo; | ||
struct json_object *schema; | ||
|
||
ret = json_object_object_get_ex(j_file, "components", &compo); | ||
if (!ret) | ||
goto err; | ||
json_object_object_get_ex(compo, "schemas", &schema); | ||
if (!ret) | ||
goto err; | ||
|
||
json_object_object_foreach(schema, k, v_) { | ||
char *new_k = strdup(k); | ||
char *resquest = strstr(new_k, suffix); | ||
|
||
if (resquest) { | ||
if (!first) | ||
putchar(' '); | ||
first = 0; | ||
*resquest = 0; | ||
printf("%s", new_k); | ||
} | ||
free(new_k); | ||
} | ||
} else { | ||
struct json_object *paths; | ||
|
||
ret = json_object_object_get_ex(j_file, "paths", &paths); | ||
if (!ret) | ||
goto err; | ||
|
||
json_object_object_foreach(paths, k, v_) { | ||
if (!first) | ||
putchar(' '); | ||
first = 0; | ||
*resquest = 0; | ||
printf("%s", new_k); | ||
printf("%s", k+1); | ||
} | ||
free(new_k); | ||
} | ||
|
||
func_ret = 0; | ||
err: | ||
json_object_put(j_file); | ||
return 0; | ||
return func_ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can modify the suffix of functions by using the
--function-suffix=FUNCTION_SUFFIX
option with the./configure
command.