This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
import { Arguments, CommandBuilder } from "yargs"; | ||
import chalk from "chalk"; | ||
import { EOL } from "os"; | ||
import { authenticate, baseOptions, userConfigNotFound } from "../shared"; | ||
import { Options } from "./queries/types"; | ||
import handlers from "./queries/handlers"; | ||
import spinner from "../services/spinner/index"; | ||
|
||
interface Options { | ||
name: string; | ||
upper?: boolean; | ||
} | ||
|
||
export const command = "greet <name>"; | ||
export const desc = "Greet <name> with Hello"; | ||
export const command = "queries <subcommand> [parameters]"; | ||
export const desc = "Operations on queries"; | ||
|
||
export const builder: CommandBuilder<Options, Options> = (yargs) => { | ||
return yargs | ||
.options({ | ||
upper: { type: "boolean" }, | ||
.options(baseOptions) | ||
.positional("subcommand", { | ||
type: "string", | ||
choices: ["list", "create"] | ||
}) | ||
.positional("name", { type: "string", demandOption: true }); | ||
.example([ | ||
["$0 queries <subcommand>"], | ||
["$0 queries <subcommand> --profile prod"] | ||
]); | ||
}; | ||
|
||
export function handler(argv: Arguments<Options>) { | ||
const { name, upper } = argv; | ||
const greeting = `Hello ${name}`; | ||
const s = upper ? greeting.toUpperCase() : greeting; | ||
process.stdout.write(chalk.green(chalk.bold(s)) + EOL); | ||
process.exit(0); | ||
export async function handler(argv: Arguments<Options>) { | ||
const { subcommand, profile = "default", json, } = argv; | ||
spinner.init(!!argv.quiet) | ||
await authenticate(profile); | ||
|
||
switch (subcommand) { | ||
case subCommand.list: | ||
await handlers.list(!!json) | ||
break; | ||
case subCommand.create: | ||
console.log("create"); | ||
break; | ||
default: | ||
process.exit(1); | ||
} | ||
} | ||
|
||
export enum subCommand { | ||
list = "list", | ||
create = "create", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import spinner from "../../services/spinner/index"; | ||
import api from "../../services/api/api"; | ||
import outputs from "./outputs"; | ||
|
||
async function list(json: boolean) { | ||
const s = spinner.get(); | ||
s.start("Fetching your queries"); | ||
const queries = await api.queriesList(); | ||
s.succeed(); | ||
outputs.list(queries, json); | ||
} | ||
|
||
export default { | ||
list, | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Query } from "../../services/api/paths/queries"; | ||
|
||
function list(queries: Query[], json: boolean) { | ||
if (json) { | ||
console.log("json"); | ||
console.log(JSON.stringify(queries)); | ||
return; | ||
} | ||
console.log("table"); | ||
console.log(queries); | ||
} | ||
|
||
export default { | ||
list, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import type { BaseOptions } from "../../shared"; | ||
|
||
export interface Options extends BaseOptions { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import auth from "./auth/auth"; | ||
import auth from "./paths/auth"; | ||
import queries from "./paths/queries"; | ||
|
||
export default { | ||
...auth, | ||
...queries, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { client } from "../clients"; | ||
|
||
|
||
export interface QueryParameters { | ||
groupBys?: string[]; | ||
namespaces?: Array<{ | ||
type: string, | ||
value: string; | ||
}>; | ||
filters?: Array<QueryFilter>; | ||
filterCombination: "AND" | "OR"; | ||
calculations: Array<{ | ||
key: string; | ||
operator: string; | ||
}>; | ||
} | ||
|
||
export interface QueryFilter { | ||
key: string; | ||
operation: string; | ||
value: string | number | boolean | { key: string; }; | ||
type: string; | ||
} | ||
|
||
export interface Query { | ||
parameters: QueryParameters, | ||
id: string; | ||
name: string; | ||
description: string; | ||
workspaceId: string; | ||
environmentId: string; | ||
userId: string; | ||
created?: string; | ||
updated?: string; | ||
} | ||
|
||
|
||
async function queriesList(): Promise<Query[]> { | ||
const res = (await client.get("/queries")).data; | ||
return res.queries; | ||
} | ||
|
||
export default { | ||
queriesList, | ||
} |