mirror of https://github.com/Seich/Beau.git
Added flags for quiet and as-json output. (#26)
--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
dbc7addb39
|
|
@ -41,7 +41,7 @@ Base.flags = {
|
||||||
}),
|
}),
|
||||||
verbose: flags.boolean({
|
verbose: flags.boolean({
|
||||||
char: 'V',
|
char: 'V',
|
||||||
description: 'Show all additional information available for a command.'
|
description: `Show all additional information available for a command.`
|
||||||
}),
|
}),
|
||||||
'no-format': flags.boolean({
|
'no-format': flags.boolean({
|
||||||
description: `Disables color formatting for usage on external tools.`
|
description: `Disables color formatting for usage on external tools.`
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,9 @@ class RequestCommand extends Base {
|
||||||
param: params,
|
param: params,
|
||||||
config,
|
config,
|
||||||
'no-format': noFormat = false,
|
'no-format': noFormat = false,
|
||||||
verbose = false
|
verbose = false,
|
||||||
|
'as-json': asJson = false,
|
||||||
|
quiet = false
|
||||||
},
|
},
|
||||||
args
|
args
|
||||||
} = this.parse(RequestCommand);
|
} = this.parse(RequestCommand);
|
||||||
|
|
@ -51,27 +53,44 @@ class RequestCommand extends Base {
|
||||||
spinnerSprite
|
spinnerSprite
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
let spinnerEnabled = !noFormat && !asJson && !quiet;
|
||||||
if (!noFormat) {
|
|
||||||
|
if (spinnerEnabled) {
|
||||||
this.spinner.start();
|
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) {
|
if (noFormat) {
|
||||||
this.log(res.response.status);
|
this.log(res.response.status);
|
||||||
this.log(res.request.endpoint);
|
this.log(res.request.endpoint);
|
||||||
this.log(JSON.stringify(res.response.headers));
|
this.log(JSON.stringify(res.response.headers));
|
||||||
this.log(JSON.stringify(res.response.body));
|
this.log(JSON.stringify(res.response.body));
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.prettyOutput(res, verbose);
|
this.prettyOutput(res, verbose);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
new Line().output();
|
|
||||||
this.spinner.stop();
|
|
||||||
this.error(err.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestCommand.description = `Executes a request by name.`;
|
RequestCommand.description = `Executes a request by name.`;
|
||||||
|
|
@ -82,6 +101,15 @@ RequestCommand.flags = {
|
||||||
multiple: true,
|
multiple: true,
|
||||||
default: [],
|
default: [],
|
||||||
description: `Allows you to inject values into the request's environment.`
|
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