Closed robbieaverill closed 4 years ago
stdin
doesn't have native support in oclif but I played around a little and came up with this patch that works pretty well:
diff --git a/src/commands/request.js b/src/commands/request.js
index 0ff7e10..d9c4fed 100644
--- a/src/commands/request.js
+++ b/src/commands/request.js
@@ -41,6 +41,29 @@ class RequestCommand extends Command {
this.error(jsonHelper.prettify(error.body))
}
}
+
+ getStdin() {
+ return new Promise(resolve => {
+ let data = ''
+
+ if (process.stdin.readableLength === 0) {
+ return resolve(undefined)
+ }
+
+ const handler = () => {
+ let chunk
+ while ((chunk = process.stdin.read()) !== null) {
+ data += chunk
+ }
+ }
+ process.stdin.on('readable', handler)
+
+ process.stdin.once('end', () => {
+ process.stdin.off('readable', handler)
+ resolve(data)
+ })
+ })
+ }
}
RequestCommand.description = `Run abstract API request
Might not make sense as a method though because you should only really use it at the start of the command before you interact with the user.
The request command doesn't need to be interactive, if that helps
Yeah, just was talking about semantics. Doesn't really matter too much. Anyway - I'll come back to this later, I don't want to distract myself with this yet 😅
PR at #22
If I want to use
chec request POST /v1/assets
to upload an asset, the file contents must be a base64 encoded string (for local uploads anyway). This easily exceeds bash's limit for length, so we could add a--file
argument (-f
short) to specify a file to load and provide as the request body. Maybe it could be JSON only for now.