mirror of https://github.com/Seich/Beau.git
Added flags for quiet and as-json output.
--as-json outputs the response as json, this allows you to use tools
like jq on the output which is nice.
--quiet makes it so no output is printed. I added this in case you are
looping Beau and don't want to see the output of every single request.
Example: `seq 10 | xargs -I{} beau request hi --quiet`.
This commit is contained in:
parent
293dde59c4
commit
139dd55c4e
|
|
@ -41,7 +41,7 @@ Base.flags = {
|
|||
}),
|
||||
verbose: flags.boolean({
|
||||
char: 'V',
|
||||
description: 'Show all additional information available for a command.'
|
||||
description: `Show all additional information available for a command.`
|
||||
}),
|
||||
'no-format': flags.boolean({
|
||||
description: `Disables color formatting for usage on external tools.`
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ class RequestCommand extends Base {
|
|||
param: params,
|
||||
config,
|
||||
'no-format': noFormat = false,
|
||||
verbose = false
|
||||
verbose = false,
|
||||
'as-json': asJson = false,
|
||||
quiet = false
|
||||
},
|
||||
args
|
||||
} = this.parse(RequestCommand);
|
||||
|
|
@ -51,27 +53,44 @@ class RequestCommand extends Base {
|
|||
spinnerSprite
|
||||
);
|
||||
|
||||
try {
|
||||
if (!noFormat) {
|
||||
let spinnerEnabled = !noFormat && !asJson && !quiet;
|
||||
|
||||
if (spinnerEnabled) {
|
||||
this.spinner.start();
|
||||
}
|
||||
|
||||
let res = await Beau.requests.execByAlias(args.alias);
|
||||
let res;
|
||||
|
||||
try {
|
||||
res = await Beau.requests.execByAlias(args.alias);
|
||||
} catch (err) {
|
||||
this.spinner.stop();
|
||||
|
||||
if (!quiet) {
|
||||
this.error(err.message);
|
||||
}
|
||||
|
||||
this.exit(1);
|
||||
}
|
||||
|
||||
if (quiet) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (asJson) {
|
||||
return this.log(JSON.stringify(res.response));
|
||||
}
|
||||
|
||||
if (noFormat) {
|
||||
this.log(res.response.status);
|
||||
this.log(res.request.endpoint);
|
||||
this.log(JSON.stringify(res.response.headers));
|
||||
this.log(JSON.stringify(res.response.body));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
this.prettyOutput(res, verbose);
|
||||
}
|
||||
} catch (err) {
|
||||
new Line().output();
|
||||
this.spinner.stop();
|
||||
this.error(err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RequestCommand.description = `Executes a request by name.`;
|
||||
|
|
@ -82,6 +101,15 @@ RequestCommand.flags = {
|
|||
multiple: true,
|
||||
default: [],
|
||||
description: `Allows you to inject values into the request's environment.`
|
||||
}),
|
||||
|
||||
quiet: flags.boolean({
|
||||
description: `Skips the output.`
|
||||
}),
|
||||
|
||||
'as-json': flags.boolean({
|
||||
char: 'j',
|
||||
description: `Outputs the response as json.`
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue