Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
added basic account command
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Oct 3, 2017
1 parent f7af1f9 commit d7c9074
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
19 changes: 7 additions & 12 deletions 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}`)
}
}
5 changes: 2 additions & 3 deletions cli/packages/graphcool-cli-core/src/commands/info/index.ts
Expand Up @@ -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({
Expand Down
6 changes: 6 additions & 0 deletions cli/packages/graphcool-cli-core/src/index.ts
Expand Up @@ -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' },
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -91,4 +96,5 @@ export const commands = [
Stop,
Up,
Restart,
Account,
]
14 changes: 14 additions & 0 deletions cli/packages/graphcool-cli-engine/src/Client/Client.ts
@@ -1,4 +1,5 @@
import {
AccountInfo,
AuthenticateCustomerPayload,
FunctionInfo,
FunctionLog,
Expand Down Expand Up @@ -73,6 +74,19 @@ export class Client {
} as any
}

async getAccount(): Promise<AccountInfo> {
const {viewer: {user}} = await this.client.request<{viewer: {user: AccountInfo}}>(`{
viewer {
user {
email
name
}
}
}`)

return user
}

async createProject(
name: string,
projectDefinition: ProjectDefinition,
Expand Down
4 changes: 4 additions & 0 deletions cli/packages/graphcool-cli-engine/src/types.ts
Expand Up @@ -144,3 +144,7 @@ export interface AuthenticateCustomerPayload {
}
}

export interface AccountInfo {
email: string
name: string
}

0 comments on commit d7c9074

Please sign in to comment.