Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into ux/command-account
Browse files Browse the repository at this point in the history
  • Loading branch information
antho1404 authored Jul 8, 2019
2 parents a0af6ec + 2a5b820 commit 7140598
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/commands/daemon/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Logs extends Command {
static flags = {
...Command.flags,
tail: flags.integer({
description: 'Output specified number of lines at the end of logs',
description: 'Display the last N lines',
default: -1
}),
follow: flags.boolean({
Expand All @@ -36,7 +36,6 @@ export default class Logs extends Command {
logs.on('error', (error: Error) => {
throw error
})

return logs
}
}
15 changes: 6 additions & 9 deletions src/commands/daemon/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import version from '../../version'
import Status, {ServiceStatus} from './status'

export default class Start extends Command {
static description = 'Start the MESG Engine\'s daemon'
static description = 'Start the Engine'

static flags = {
...Command.flags,
version: flags.string({
description: 'Version of the engine to run',
description: 'Version of the Engine to run',
required: true,
default: version.engine
}),
Expand All @@ -34,30 +34,27 @@ export default class Start extends Command {
async run() {
const {flags} = this.parse(Start)

const status = await Status.run(['--name', flags.name])
const status = await Status.run(['--name', flags.name, '--silent'])
if (status === ServiceStatus.STARTED) {
this.log('Engine is already started')
return false
}
this.spinner.start('MESG Engine')
this.spinner.start('Starting Engine')
const eventPromise = this.waitForEvent(({Action, Type, from}) =>
Type === 'container' &&
Action === 'start' &&
from === `mesg/engine:${flags.version}`
)
this.spinner.status = 'Creating network'
const network = await this.getOrCreateNetwork({name: flags.name})
this.spinner.status = 'Creating service'
await this.createService(network, {
name: flags.name,
version: flags.version,
colors: flags['log-force-colors'],
format: flags['log-format'],
level: flags['log-level']
})
this.spinner.status = 'Waiting service to start'
await eventPromise
this.spinner.stop('Started')

this.spinner.stop()
return true
}
}
3 changes: 1 addition & 2 deletions src/commands/daemon/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export default class Status extends Command {

async run() {
const {flags} = this.parse(Status)
this.spinner.start('MESG Engine')
this.spinner.status = 'Fetching services'
this.spinner.start('Engine is')
const services = await this.listServices({name: flags.name})
if (services.length === 0) {
this.spinner.stop('stopped')
Expand Down
14 changes: 6 additions & 8 deletions src/commands/daemon/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Command from '../../docker-command'
import Status, {ServiceStatus} from './status'

export default class Stop extends Command {
static description = 'Stop the MESG Engine\'s daemon'
static description = 'Stop the Engine'

static flags = {
...Command.flags
Expand All @@ -12,25 +12,23 @@ export default class Stop extends Command {
async run() {
const {flags} = this.parse(Stop)

const status = await Status.run(['--name', flags.name])
const status = await Status.run(['--name', flags.name, '--silent'])
if (status === ServiceStatus.STOPPED) {
this.log('Engine is already stopped')
return false
}
this.spinner.start('MESG Engine')
this.spinner.status = 'Fetching services'
this.spinner.start('Stopping Engine')
const services = await this.listServices({name: flags.name})
if (services.length === 0) return
if (services.length === 0) return false
const service = services[0]
const eventPromise = this.waitForEvent(({Action, from, Type}) =>
Type === 'container' &&
Action === 'destroy' &&
from === (service.data as any).Spec.TaskTemplate.ContainerSpec.Image
)
this.spinner.status = 'Removing service'
await service.remove()
await eventPromise
this.spinner.stop('stopped')

this.spinner.stop()
return true
}
}
12 changes: 5 additions & 7 deletions src/commands/marketplace/create-offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ import {flags} from '@oclif/command'
import Command from '../../marketplace-command'

export default class MarketplaceCreateOffer extends Command {
static description = 'Create a new offer on a service on the MESG Marketplace'
static description = 'Create an offer of a service'

static flags = {
...Command.flags,
price: flags.string({
description: 'Price (in MESG token) of the offer to create',
description: 'Price (in MESG tokens)',
required: true,
}),
duration: flags.string({
description: 'Duration (in second) of the offer to create',
description: 'Duration (in seconds)',
required: true,
}),
}

static args = [{
name: 'SID',
description: 'SID of the service on the MESG Marketplace',
description: 'SID of the service',
required: true,
}]

async run() {
const {args, flags} = this.parse(MarketplaceCreateOffer)

const account = await this.getAccount()
const passphrase = await this.getPassphrase()
this.spinner.start('Creating offer')
Expand All @@ -45,8 +44,7 @@ export default class MarketplaceCreateOffer extends Command {
taskKey: 'publishCreateServiceOffer',
inputs: JSON.stringify(signedTx)
})
this.spinner.stop('Offer created')

this.spinner.stop()
this.styledJSON(offer)
return offer
}
Expand Down
18 changes: 8 additions & 10 deletions src/commands/marketplace/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ServiceCreate from '../service/create'
import ServiceDetail from '../service/detail'

export default class MarketplacePublish extends Command {
static description = 'Publish a service on the MESG Marketplace'
static description = 'Publish a service'

static flags = {
...Command.flags
Expand All @@ -27,13 +27,10 @@ export default class MarketplacePublish extends Command {

const account = await this.getAccount()

this.spinner.start('Compile service')
this.spinner.start('Preparing service')
const compiledService = await ServiceCompile.run([path, '--silent'])

const createResponse = await ServiceCreate.run([JSON.stringify(compiledService), '--silent'])
const definition = await ServiceDetail.run([createResponse.hash, '--silent'])

this.spinner.status = 'Preparing service'
const serviceTx = await this.preparePublishService({
definition,
readme: this.lookupReadme(path),
Expand All @@ -44,15 +41,16 @@ export default class MarketplacePublish extends Command {
source: definition.source
}
}, account)
this.spinner.stop('ready')
if (!await cli.confirm(`Ready to send a transaction to ${serviceTx.to} with the account ${account}?`)) {
this.spinner.stop()

if (!await cli.confirm(`Do you confirm to send a transaction to ${serviceTx.to} with the account ${account}?`)) {
return null
}
const passphrase = await this.getPassphrase()

this.spinner.start('Publish service')

const passphrase = await this.getPassphrase()
this.spinner.start('Publishing service')
const marketplaceService = await this.publishService(account, serviceTx, passphrase)
this.spinner.stop()
this.styledJSON(marketplaceService)
return marketplaceService
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/marketplace/purchase.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Command from '../../marketplace-command'

export default class MarketplacePurchase extends Command {
static description = 'Purchase a service on the MESG Marketplace'
static description = 'Purchase a service'

static flags = {
...Command.flags,
}

static args = [{
name: 'SID',
description: 'ID of the service on the MESG Marketplace',
description: 'ID of the service',
required: true,
}, {
name: 'OFFER_ID',
description: 'ID of the offer on the MESG Marketplace',
description: 'ID of the offer',
required: true,
}]

Expand Down

0 comments on commit 7140598

Please sign in to comment.