From d7c9074659889bf751c79657cde32b78d205137a Mon Sep 17 00:00:00 2001 From: timsuchanek Date: Tue, 3 Oct 2017 16:36:00 +0200 Subject: [PATCH] added basic account command --- .../src/commands/account/index.ts | 19 +++++++------------ .../src/commands/info/index.ts | 5 ++--- cli/packages/graphcool-cli-core/src/index.ts | 6 ++++++ .../graphcool-cli-engine/src/Client/Client.ts | 14 ++++++++++++++ .../graphcool-cli-engine/src/types.ts | 4 ++++ 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/cli/packages/graphcool-cli-core/src/commands/account/index.ts b/cli/packages/graphcool-cli-core/src/commands/account/index.ts index f7ac6a7fe1..54d76c65af 100644 --- a/cli/packages/graphcool-cli-core/src/commands/account/index.ts +++ b/cli/packages/graphcool-cli-core/src/commands/account/index.ts @@ -1,19 +1,14 @@ import { Command, flags, Flags } from 'graphcool-cli-engine' -export default class Info extends Command { - static topic = 'info' +export default class Account extends Command { + static topic = 'account' static description = 'Get info about the current account' - static flags: Flags = { - env: flags.string({ - char: 'e', - description: 'Environment name to set', - }), - project: flags.string({ - char: 'p', - description: 'Project Id to set', - }), - } async run() { await this.auth.ensureAuth() + const account = await this.client.getAccount() + + this.out.log(`\ +Email: ${account.email} +Name: ${account.name}`) } } diff --git a/cli/packages/graphcool-cli-core/src/commands/info/index.ts b/cli/packages/graphcool-cli-core/src/commands/info/index.ts index 8640c7fc20..b99dc84f80 100644 --- a/cli/packages/graphcool-cli-core/src/commands/info/index.ts +++ b/cli/packages/graphcool-cli-core/src/commands/info/index.ts @@ -9,9 +9,8 @@ import { import * as chalk from 'chalk' import { printPadded, subscriptionURL } from '../../util' -export default class ProjectInfoCommand extends Command { - static topic = 'projects' - static command = 'info' +export default class InfoCommand extends Command { + static topic = 'info' static description = 'Print project info (environments, endpoints, ...) ' static flags: Flags = { env: flags.string({ diff --git a/cli/packages/graphcool-cli-core/src/index.ts b/cli/packages/graphcool-cli-core/src/index.ts index f4a938c0b5..6a20c56fa7 100644 --- a/cli/packages/graphcool-cli-core/src/index.ts +++ b/cli/packages/graphcool-cli-core/src/index.ts @@ -23,6 +23,7 @@ import Start from './commands/local/start' import Stop from './commands/local/stop' import Up from './commands/local/up' import Restart from './commands/local/restart' +import Account from './commands/account' export const topics = [ { name: 'deploy', description: 'Deploy local project definition' }, @@ -59,6 +60,10 @@ export const topics = [ name: 'invoke', description: 'Invokes a function locally', }, + { + name: 'account', + description: 'Information about the current authenticated account' + } // { // name: 'local', // description: 'Manage the local Graphcool version' @@ -91,4 +96,5 @@ export const commands = [ Stop, Up, Restart, + Account, ] diff --git a/cli/packages/graphcool-cli-engine/src/Client/Client.ts b/cli/packages/graphcool-cli-engine/src/Client/Client.ts index 98dc9d2476..ff30595621 100644 --- a/cli/packages/graphcool-cli-engine/src/Client/Client.ts +++ b/cli/packages/graphcool-cli-engine/src/Client/Client.ts @@ -1,4 +1,5 @@ import { + AccountInfo, AuthenticateCustomerPayload, FunctionInfo, FunctionLog, @@ -73,6 +74,19 @@ export class Client { } as any } + async getAccount(): Promise { + const {viewer: {user}} = await this.client.request<{viewer: {user: AccountInfo}}>(`{ + viewer { + user { + email + name + } + } + }`) + + return user + } + async createProject( name: string, projectDefinition: ProjectDefinition, diff --git a/cli/packages/graphcool-cli-engine/src/types.ts b/cli/packages/graphcool-cli-engine/src/types.ts index 7ce6c3efb4..1a968939d0 100644 --- a/cli/packages/graphcool-cli-engine/src/types.ts +++ b/cli/packages/graphcool-cli-engine/src/types.ts @@ -144,3 +144,7 @@ export interface AuthenticateCustomerPayload { } } +export interface AccountInfo { + email: string + name: string +}