Skip to content

Commit

Permalink
move listProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-marky committed Sep 4, 2023
1 parent 343df90 commit a3c7fb9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import chalk from 'chalk'
import { Command } from 'commander'

import { loadProcesses, disableProcess } from './lib/process/index.js'
import { loadProcesses, disableProcess, listProcess } from './lib/process/index.js'
import { getAll } from './lib/process/api.js'
import cliVersion from './version.js'
import { listHelper } from './lib/utils/cliHelper.js'


const { log, dir } = console
const program = new Command()
Expand Down Expand Up @@ -61,7 +59,7 @@ program
const res: Process.RawPayload[] = await getAll(mapOptions(options))
let processes: Process.RawPayload[]

listHelper(res, processes, options)
listProcess(res, processes, options)

process.exit(0)
} catch (err) {
Expand All @@ -74,6 +72,7 @@ program
.command('create')
.description('A command for persisting process flows onto the chain')
.option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')
.option('--verbose', 'Returns all information about the transation, default - false')
.option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
.option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
.requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
Expand Down
30 changes: 30 additions & 0 deletions src/lib/process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@ export const loadProcesses = async ({
return res
}

export const listProcess = async (
res: Process.RawPayload[],
processes: Process.RawPayload[],
options: Process.CLIOptions) => {
const { dir } = console
if (options.active) {
processes = res.filter(({ status }) => status === 'Enabled')
} else if (options.disabled) {
processes = res.filter(({ status }) => status === 'Disabled')
} else {
processes = res
}

if (options.raw) {
dir(processes, { depth: null })
} else{
dir(
processes.map((p) => {
return {
id: p.id,
version: p.version,
status: p.status,
...options.verbose ? { program: p.program } : { }
}
}),
{ depth: null }
)
}
}

export const createProcess = async (
name: string,
version: number,
Expand Down
26 changes: 0 additions & 26 deletions src/lib/utils/cliHelper.ts

This file was deleted.

0 comments on commit a3c7fb9

Please sign in to comment.