Socket
Socket
Sign inDemoInstall

groq-cli

Package Overview
Dependencies
83
Maintainers
14
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

2

package.json
{
"name": "groq-cli",
"version": "0.2.0",
"version": "0.2.1",
"description": "Run GROQ in the command line",

@@ -5,0 +5,0 @@ "license": "MIT",

#!/usr/bin/env node
/* eslint-disable id-length, no-process-exit */
require("regenerator-runtime/runtime")
require('regenerator-runtime/runtime')
const meow = require('meow')
const { parse, evaluate } = require('groq-js')
const {parse, evaluate} = require('groq-js')
const getStdin = require('get-stdin')

@@ -20,6 +20,6 @@ const chalk = require('chalk')

Options
${chalk.green(`-i, --input One of: ndjson, json, null`)}
${chalk.green(`-o, --output One of: ndjson, json, pretty`)}
${chalk.green(`-p, --pretty Shortcut for --output=pretty`)}
${chalk.green(`-n, --ndjson Shortcut for --input=ndjson --output=ndjson`)}
${chalk.green(`-i, --input`)} One of: ndjson, json, null
${chalk.green(`-o, --output`)} One of: ndjson, json, pretty
${chalk.green(`-p, --pretty`)} Shortcut for --output=pretty
${chalk.green(`-n, --ndjson`)} Shortcut for --input=ndjson --output=ndjson

@@ -74,3 +74,3 @@ Input formats

function handleError (error) {
function handleError(error) {
console.error(chalk.red(error))

@@ -82,17 +82,15 @@ process.emit('SIGINT')

if (!choices.includes(input)) {
throw Error(chalk.yellow(`Unknown ${title}: ${input}. Valid choices are: ${choices.join(', ')}.`))
throw Error(
chalk.yellow(`Unknown ${title}: ${input}. Valid choices are: ${choices.join(', ')}.`)
)
}
}
function check ({ query, inputFormat, outputFormat }) {
function check({query, inputFormat, outputFormat}) {
if (!query) {
throw Error(
chalk.yellow(
'You must add a query. To learn more, run\n\n $ groq --help'
)
)
throw Error(chalk.yellow('You must add a query. To learn more, run\n\n $ groq --help'))
}
validateChoice("input format", inputFormat, ['json', 'ndjson', 'null'])
validateChoice("output format", outputFormat, ['json', 'ndjson', 'pretty'])
validateChoice('input format', inputFormat, ['json', 'ndjson', 'null'])
validateChoice('output format', outputFormat, ['json', 'ndjson', 'pretty'])

@@ -104,3 +102,3 @@ return true

yield JSON.stringify(await result.get())
yield "\n"
yield '\n'
}

@@ -110,3 +108,3 @@

yield colorizeJson(await result.get())
yield "\n"
yield '\n'
}

@@ -118,7 +116,7 @@

yield JSON.stringify(await value.get())
yield "\n"
yield '\n'
}
} else {
yield JSON.stringify(await result.get())
yield "\n"
yield '\n'
}

@@ -130,7 +128,8 @@ }

pretty: outputPrettyJSON,
ndjson: outputNDJSON,
ndjson: outputNDJSON
}
async function inputJSON() {
const dataset = JSON.parse(await getStdin())
const input = await getStdin()
const dataset = input === '' ? null : JSON.parse(input)
return {dataset, root: dataset}

@@ -144,11 +143,16 @@ }

function inputNull() {
return {}
}
const INPUTTERS = {
json: inputJSON,
ndjson: inputNDJSON,
null: inputNull
}
async function* runQuery() {
const { flags, input } = cli
const { pretty, ndjson: isNdjson } = flags
let { input: inputFormat, output: outputFormat } = flags
const {flags, input} = cli
const {pretty, ndjson: isNdjson} = flags
let {input: inputFormat, output: outputFormat} = flags

@@ -166,3 +170,3 @@ const query = input[0]

check({ query, inputFormat, outputFormat })
check({query, inputFormat, outputFormat})

@@ -169,0 +173,0 @@ // Parse query

@@ -14,4 +14,3 @@ const tokenize = require('json-lexer')

function colorize(input) {
const data = typeof input === 'string' ? JSON.parse(input) : input
const json = JSON.stringify(data, null, 2)
const json = JSON.stringify(input, null, 2)

@@ -18,0 +17,0 @@ return tokenize(json)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc