|
| 1 | +import * as cmd from "commander"; |
| 2 | +import { ELogLevel, getLogger } from "../../utils/logger_util.js"; |
| 3 | +import { spinnerError, spinnerSuccess, updateSpinnerText } from "../../utils/spinner_util.js"; |
| 4 | +import { addGlobalOptions } from "../../utils/options_util.js"; |
| 5 | +import { getIdToken } from "../../utils/auth_util.js"; |
| 6 | +import { combineOptsWithSettings } from "../../utils/config_util.js"; |
| 7 | +import { outputResults } from "../../utils/output_util.js"; |
| 8 | +import { runBoilingQuery } from "../../../integration/boilingdata/query.js"; |
| 9 | + |
| 10 | +const logger = getLogger("bdcli-api"); |
| 11 | +logger.setLogLevel(ELogLevel.WARN); |
| 12 | + |
| 13 | +async function query(options: any, _command: cmd.Command): Promise<void> { |
| 14 | + try { |
| 15 | + options = await combineOptsWithSettings(options, logger); |
| 16 | + |
| 17 | + updateSpinnerText("Authenticating"); |
| 18 | + const { idToken: token, cached, region } = await getIdToken(logger); |
| 19 | + updateSpinnerText(cached ? "Authenticating: cached" : "Authenticating: success"); |
| 20 | + spinnerSuccess(); |
| 21 | + |
| 22 | + updateSpinnerText("Sending Query to Boiling API"); |
| 23 | + const results = await runBoilingQuery(options.sql, token, region, logger); |
| 24 | + spinnerSuccess(); |
| 25 | + await outputResults(results, options.disableSpinner); |
| 26 | + } catch (err: any) { |
| 27 | + spinnerError(err?.message); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +const program = new cmd.Command("bdcli api query") |
| 32 | + .addOption(new cmd.Option("--sql <sqlQuery>", "SQL clause").makeOptionMandatory()) |
| 33 | + .action(async (options, command) => await query(options, command)); |
| 34 | + |
| 35 | +(async () => { |
| 36 | + await addGlobalOptions(program, logger); |
| 37 | + await program.parseAsync(process.argv); |
| 38 | +})(); |
0 commit comments