oh api applies -X without a body too (closes #75) 1b770a1fecf0
oh api PATH -X POST sent a GET unless -d was given. Without a body, a GET still reads, and any other method now sends an empty JSON object.
- Author
- Andy McCall @andymccall <[email protected]>
- When
- · 2026-10-02 01:56 UTC
- Signature
- ✔ signed by Andy McCall
- Hash
1b770a1fecf00ba25f4dec05fffd399e8805234618e48ded335d64c955bb5374- Depends on
- 5c6e92fd8d71
- Depended on by
- nothing yet
- In bookmarks
- api-unknown-fields cancel-landed-runs clear-waiting close-proposal-140 diffusion-pin-bookmark draft-ready image-check job-waits main oh-comment-body-file proposal-list-fast run-one-job wiki-says-so
- In tags
- v0.3.0 v0.3.1 v0.4.0 v0.4.1 v0.4.2 v0.5.0 v0.5.1 v0.5.2 v0.6.0 v0.6.1 v0.7.0 v0.8.0 v0.9.0 v0.9.1 v0.9.11 v0.9.15 v0.9.16 v0.9.19 v0.9.2 v0.9.20 v0.9.21 v0.9.22 v0.9.23 v0.9.24 v0.9.3 v0.9.4 v0.9.5 v0.9.6 v0.9.7 v0.9.8 v0.9.9
- Edits
- 3 atoms, 0 tree operations, 1 file
Browse the tree at this change
modified crates/oh/src/main.rs +4 −1
| … | 262 unchanged lines |
||
| 263 | 263 | Cmd::Auth { .. } => unreachable!(), |
|
| 264 | 264 | Cmd::Api { path, method, data } => { |
|
| 265 | 265 | let path = if path.starts_with('/') { path } else { format!("/{path}") }; |
|
| 266 | + | // The method applies with or without a body (#75): without one, a |
|
| 267 | + | // GET reads, anything else sends an empty object. |
|
| 266 | 268 | let text = match data { |
|
| 267 | 269 | Some(d) => c.send_text( |
|
| 268 | 270 | &method.to_uppercase(), |
|
| 269 | 271 | &path, |
|
| 270 | 272 | &serde_json::from_str::<serde_json::Value>(&d).context("--data is not JSON")?, |
|
| 271 | 273 | )?, |
|
| 272 | - | None => c.get_text(&path)?, |
|
| 274 | + | None if method.eq_ignore_ascii_case("GET") => c.get_text(&path)?, |
|
| 275 | + | None => c.send_text(&method.to_uppercase(), &path, &serde_json::json!({}))?, |
|
| 273 | 276 | }; |
|
| 274 | 277 | println!("{text}"); |
|
| 275 | 278 | Ok(0) |
|
| … | 442 unchanged lines |