Skip to content

Commit

Permalink
feat(cli): show elapsed time for each step (#620)
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <[email protected]>
  • Loading branch information
leninmehedy authored Dec 9, 2023
1 parent 88060ed commit af42af8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 19 deletions.
15 changes: 12 additions & 3 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class ChartCommand extends BaseCommand {
)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -125,7 +128,10 @@ export class ChartCommand extends BaseCommand {
await self.chartManager.uninstall(ctx.config.namespace, constants.CHART_FST_DEPLOYMENT_NAME)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -167,7 +173,10 @@ export class ChartCommand extends BaseCommand {
)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
20 changes: 16 additions & 4 deletions fullstack-network-manager/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ export class ClusterCommand extends BaseCommand {
self.logger.showList('Kubernetes Contexts', ctx.kubeContexts)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -203,7 +206,10 @@ export class ClusterCommand extends BaseCommand {
},
skip: (ctx, _) => !ctx.clusters.includes(ctx.config.clusterName)
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -289,7 +295,10 @@ export class ClusterCommand extends BaseCommand {
},
skip: (ctx, _) => ctx.isChartInstalled
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -337,7 +346,10 @@ export class ClusterCommand extends BaseCommand {
},
skip: (ctx, _) => !ctx.isChartInstalled
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
5 changes: 4 additions & 1 deletion fullstack-network-manager/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export class InitCommand extends BaseCommand {
self.logger.showJSON('Cached Config', ctx.config)
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
18 changes: 13 additions & 5 deletions fullstack-network-manager/src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class NodeCommand extends BaseCommand {
}
], {
concurrent: false,
showErrorMessage: false
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
Expand Down Expand Up @@ -189,12 +189,16 @@ export class NodeCommand extends BaseCommand {
return task.newListr(subTasks, {
concurrent: true,
rendererOptions: {
collapseSubtasks: false
collapseSubtasks: false,
timer: constants.LISTR_DEFAULT_RENDERER_TIMER_OPTION
}
})
}
}
], { concurrent: false })
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -238,12 +242,16 @@ export class NodeCommand extends BaseCommand {
return task.newListr(subTasks, {
concurrent: true,
rendererOptions: {
collapseSubtasks: false
collapseSubtasks: false,
timer: constants.LISTR_DEFAULT_RENDERER_TIMER_OPTION
}
})
}
}
], { concurrent: false })
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
10 changes: 8 additions & 2 deletions fullstack-network-manager/src/commands/relay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export class RelayCommand extends BaseCommand {
this.logger.showList('Deployed Relays', await self.chartManager.getInstalledCharts(namespace))
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down Expand Up @@ -190,7 +193,10 @@ export class RelayCommand extends BaseCommand {
this.logger.showList('Deployed Relays', await self.chartManager.getInstalledCharts(namespace))
}
}
])
], {
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
})

try {
await tasks.run()
Expand Down
18 changes: 18 additions & 0 deletions fullstack-network-manager/src/core/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { color, PRESET_TIMER } from 'listr2'
import { dirname, normalize } from 'path'
import { fileURLToPath } from 'url'
import chalk from 'chalk'
Expand Down Expand Up @@ -53,3 +54,20 @@ export const DEFAULT_CHART_REPO = new Map()
.set(CHART_FST_REPO_NAME, CHART_REPO_FST_URL)
.set(CHART_JSON_RPC_RELAY_REPO_NAME, CHART_REPO_JSON_RPC_RELAY_URL)
.set(CHART_MIRROR_NODE_REPO_NAME, CHART_MIRROR_NODE_URL)

// Listr related
export const LISTR_DEFAULT_RENDERER_TIMER_OPTION = {
...PRESET_TIMER,
condition: (duration) => duration > 100,
format: (duration) => {
if (duration > 10000) {
return color.red
}

return color.green
}
}

export const LISTR_DEFAULT_RENDERER_OPTION = {
timer: LISTR_DEFAULT_RENDERER_TIMER_OPTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ describe('ShellRunner', () => {
it('should run command', async () => {
await shellRunner.run('ls -l')
expect(loggerSpy).toHaveBeenNthCalledWith(1, 'Executing command: \'ls -l\'')
expect(loggerSpy).toHaveBeenNthCalledWith(2,'Finished executing: \'ls -l\'', {
'commandExitCode': expect.any(Number),
'commandExitSignal': null,
'commandOutput': expect.any(Array)
expect(loggerSpy).toHaveBeenNthCalledWith(2, 'Finished executing: \'ls -l\'', {
commandExitCode: expect.any(Number),
commandExitSignal: null,
commandOutput: expect.any(Array)
})
expect(readableSpy).toHaveBeenCalledWith('data', expect.anything())
expect(childProcessSpy).toHaveBeenCalledWith('exit', expect.anything())
Expand Down

0 comments on commit af42af8

Please sign in to comment.