Skip to content
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

Add CLI alias for standard in #606

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

augustuswm
Copy link
Contributor

@augustuswm augustuswm commented Oct 16, 2023

  • Adds - as an alias for standard in when specifying a json body

This mirrors how the api method of the oxide.rs CLI functions. Body handling now looks like (for some type T):

 if let Some(value) = matches.get_one::<String>("json-body") {
    let body_value: types::WorkerAddOutput = match value.as_str() {
        "-" => serde_json::from_reader(std::io::stdin()).unwrap(),
        file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(),
    };
    request = request.body(body_value);
}

@augustuswm augustuswm requested a review from ahl October 17, 2023 15:30
Comment on lines 482 to 490
use std::io::Read;
let body_input = match value.as_str() {
"-" => {
let mut buf = Vec::new();
std::io::stdin().read_to_end(&mut buf).unwrap();
buf
}
file => std::fs::read(&file).unwrap()
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, updated it to use from_reader in both branches. Before merging though I would like to see if I can get a test in here. I don't think anything currently tests if a generated CLI would actually compile.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great

@ahl
Copy link
Collaborator

ahl commented Oct 23, 2023

@augustuswm as I recall you were going to add a test; no rush, just wanted to make sure you weren't blocked on me.

@augustuswm
Copy link
Contributor Author

Correct, not blocked. On me to get that added.

@augustuswm
Copy link
Contributor Author

augustuswm commented Nov 1, 2023

Added a rough pass at a compilation test. It is pretty much just a macro to generates tokens for each sdk and cli. These are then wrapped in tests that will fail to compile if the generated code fails to compile. The rest of the changes are largely bringing in the dev dependencies that the generated sdks and clis need to compile. There is probably a much more elegant way to construct these tests, but this is the first thing that came to mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants