Skip to content

Commit

Permalink
feat(cli): add info command
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucharz committed Aug 21, 2018
1 parent 4ba93f4 commit e3637b5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ const setup = async () => {
program
.version(pjson.version)

program
.command('info')
.group('Basics')
.description('Info about current project/instance/user etc.')
.action(async (...options) => {
trackAndDebug(options)
new commands.Info(context).run(options)
})

program
.command('init')
.group('Basics')
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Attach from './attach'
import Info from './info'
import Init from './init'
import Login from './login'
import Logout from './logout'
Expand Down Expand Up @@ -27,6 +28,7 @@ import InstanceDelete from './instance-delete'

export default {
Attach,
Info,
Init,
Login,
Logout,
Expand Down
49 changes: 49 additions & 0 deletions packages/cli/src/commands/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import format from 'chalk'

import logger from '../utils/debug'
import { echo, echon, warning} from '../utils/print-tools'

const { debug } = logger('cmd-info')

export default class InfoCmd {
constructor (context) {
debug('InfoCmd.constructor')
this.context = context
this.session = context.session
this.Init = context.Init
}

async run ([cmd]) {
echo()
echon(2)(` ${format.dim('username')}:`)
echo(` ${format.cyan(this.session.userEmail)}`)

echon(2)(` ${format.dim('full name')}:`)
echo(` ${format.cyan(this.session.getFullName())}`)

if (this.session.project && this.session.project.instance) {
echon(2)(`${format.dim('current instance')}:`)
echo(` ${format.cyan(this.session.project.instance)}`)
}
echon(2)(` ${format.dim('api url')}:`)
echo(` ${format.cyan(this.session.HOST)}`)

const instances = await this.session.getInstances()
if (instances.length < 1) {
echo()
echo(4)('You don\'t have any instances!')
echo()
} else {
echo(2)(` ${format.dim('all instances')}:`)
instances.forEach(instance => {
echo(18)(`- ${format.cyan(instance.name)}`)
})
echo()
}

if (!this.session.project) {
warning(2)('No Syncano project in current folder!')
echo()
}
}
}
7 changes: 7 additions & 0 deletions packages/cli/src/utils/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export class Session {
this.ENDPOINT_HOST = this.HOST === 'api.syncano.io' ? 'syncano.space' : 'syncano.link'
}

getFullName() {
return `${this.userFirstName} ${this.userLastName}`
}

getSpaceHost () {
if (this.project && this.project.instance) {
return `${this.project.instance}.${this.ENDPOINT_HOST}`
Expand Down Expand Up @@ -101,6 +105,9 @@ export class Session {
try {
const details = await this.connection.account.get(this.settings.account.getAuthKey())
this.userId = details.id
this.userEmail = details.email
this.userFirstName = details.first_name
this.userLastName = details.last_name
} catch (err) {}
}

Expand Down

0 comments on commit e3637b5

Please sign in to comment.