Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbosity to the command line #112

Merged
merged 30 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e182b61
First Commit
nitro-marky Aug 30, 2023
2ec2db9
Verbose test
nitro-marky Aug 30, 2023
b1ccaa7
Verbose true or false
nitro-marky Aug 30, 2023
a3abaf1
Verbose set to false
nitro-marky Aug 31, 2023
cb5fdb4
Rearrange verbose if statements
nitro-marky Aug 31, 2023
50a6b09
Rearrange verbose if statements
nitro-marky Aug 31, 2023
3359227
Add verbose to cli
nitro-marky Aug 31, 2023
e8312d3
Small change
nitro-marky Aug 31, 2023
86aedfb
update release flow
nitro-marky Aug 31, 2023
537de5c
Version strangeness
nitro-marky Aug 31, 2023
d0b1078
Merge branch 'main' into feat/verbose
nitro-marky Aug 31, 2023
cb122cb
Merge branch 'main' into feat/verbose
nitro-marky Sep 4, 2023
f70ca9a
Version
nitro-marky Sep 4, 2023
343df90
CLI helper
nitro-marky Sep 4, 2023
a3c7fb9
move listProcess
nitro-marky Sep 4, 2023
e4483b8
Remove dir from ListProcess
nitro-marky Sep 4, 2023
b2f89db
add verbose to create
nitro-marky Sep 4, 2023
9f662be
comments
nitro-marky Sep 4, 2023
494232d
remove filtering object creation
nitro-marky Sep 4, 2023
8b94f13
naming
nitro-marky Sep 4, 2023
ce587c4
Tidying api
nitro-marky Sep 7, 2023
d8a6f6e
Logic change
nitro-marky Sep 7, 2023
6b8cdf7
Pass test
nitro-marky Sep 7, 2023
ba7a692
L3-134: some unit tests examples.
n3op2 Sep 7, 2023
398ea87
Merge Fork
nitro-marky Sep 7, 2023
3f9177c
Merge branch 'main' into feat/verbose
nitro-marky Sep 7, 2023
280ab27
Remove comments
nitro-marky Sep 8, 2023
c85644b
Merge branch 'feat/verbose' of https://github.com/digicatapult/dscp-p…
nitro-marky Sep 8, 2023
1b31c5a
Remove comments
nitro-marky Sep 8, 2023
1389da0
Merge branch 'main' into feat/verbose
nitro-marky Sep 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ jobs:
version: ${{ steps.get_version.outputs.VERSION }}
build_date: ${{ steps.get_version.outputs.BUILD_DATE }}
is_prerelease: ${{ steps.get_version.outputs.IS_PRERELEASE }}

steps:
- uses: actions/checkout@v3
- name: Check version
id: get_version
uses: digicatapult/check-version@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

publish-gh:
name: 'Publish Github package'
needs:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/dscp-process-management",
"version": "1.7.43",
"version": "1.7.44",
"description": "DSCP Process Management Flow",
"main": "./lib/index.js",
"bin": {
Expand Down
39 changes: 8 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import chalk from 'chalk'
import { Command } from 'commander'

import { loadProcesses, disableProcess } from './lib/process/index.js'
import { loadProcesses, disableProcess, listTransforming } from './lib/process/index.js'
import { getAll } from './lib/process/api.js'
import cliVersion from './version.js'

Expand Down Expand Up @@ -42,46 +42,24 @@ program
program
.command('list')
.description('A command for listing all active process flows')
.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')
.option('--raw', 'print processes with hex values and extra keys such as "createdAtHash"')
.option('--active', 'returns only active process flows')
.option('--disabled', 'returns only disabled process flows')
.option('--print', 'print debugging info')
.action(async (options: Process.CLIOptions) => {

if (options.print)
log(`
retrieving all process flows from a chain...
options: ${b(JSON.stringify(options))}
`)
try {
const res: Process.RawPayload[] = await getAll(mapOptions(options))
const { raw, active, disabled } = options

let processes: Process.RawPayload[]
nitro-marky marked this conversation as resolved.
Show resolved Hide resolved
if (active) {
processes = res.filter(({ status }) => status === 'Enabled')
} else if (disabled) {
processes = res.filter(({ status }) => status === 'Disabled')
} else {
processes = res
}

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

listTransforming(res, processes, options)

process.exit(0)
} catch (err) {
Expand All @@ -94,9 +72,9 @@ 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')
.option('--print', 'print debugging info')
.requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
.argument('<json>', `takes JSON as string example: '${example}'`)
.action(async (data: string, options: Process.CLIOptions) => {
Expand All @@ -106,9 +84,9 @@ program
options: ${b(JSON.stringify(options))}
program: ${b(data)}
`)
const { dryRun } = options
const { dryRun, verbose } = options
try {
const res: Process.Response = await loadProcesses({ data, dryRun, options: mapOptions(options) })
const res: Process.Response = await loadProcesses({ data, dryRun, options: mapOptions(options), verbose })
n3op2 marked this conversation as resolved.
Show resolved Hide resolved
dir(res, { depth: null })
process.exit(0)
} catch (err) {
Expand All @@ -123,7 +101,6 @@ program
.option('--dryRun', 'to validate process and response locally before persisting on the chain, 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')
.option('--print', 'print debugging info')
.requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
.argument('<id>', 'a valid process id that you would like to disable')
.argument('<version>', 'a version number of a process')
Expand Down
11 changes: 9 additions & 2 deletions src/lib/process/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const createProcessTransaction = async (
polkadot: Polkadot.Polkadot,
processId: string,
program: Process.Program,
options: Polkadot.Options
options: Polkadot.Options,
verbose?: boolean
): Promise<Process.Payload> => {
const sudo = polkadot.keyring.addFromUri(options.USER_URI)

Expand All @@ -43,6 +44,11 @@ export const createProcessTransaction = async (
program,
}

if(verbose == false)
{
delete newProcess.program
nitro-marky marked this conversation as resolved.
Show resolved Hide resolved
}

unsub()
resolve(newProcess)
}
Expand Down Expand Up @@ -125,7 +131,8 @@ export const getVersion = async (polkadot: Polkadot.Polkadot, processId: string)
export const getProcess = async (
polkadot: Polkadot.Polkadot,
processId: string,
version: number
version: number,
verbose: boolean = false
): Promise<Process.Payload> => {
const result = await polkadot.api.query.processValidation.processModel(processId, version)
const data = Object(result.toHuman())
Expand Down
40 changes: 37 additions & 3 deletions src/lib/process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,59 @@ export const loadProcesses = async ({
data,
options,
dryRun,
verbose,
}: {
data: string
options?: Polkadot.Options
dryRun?: boolean
verbose?: boolean
}): Promise<Process.Response> => {
const res: Process.Response = {}
const processes: Process.CLIParsed = JSON.parse(data)
// TODO more elegant promise.series way.
for (let i = 0; i < processes.length; i++) {
const { name, version, program } = processes[i]
res[name] = await createProcess(name, version, program, dryRun, options)
res[name] = await createProcess(name, version, program, dryRun, options, verbose)
}

return res
}

export const listTransforming = async (
res: Process.RawPayload[],
processes: Process.RawPayload[],
options: Process.CLIOptions) => {
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) {
return processes
} else{
return(
nitro-marky marked this conversation as resolved.
Show resolved Hide resolved
processes.map((p) => {
return {
id: p.id,
version: p.version,
status: p.status,
...options.verbose ? { program: p.program } : { }
}
})
)
}
}

export const createProcess = async (
name: string,
version: number,
userProgram: Process.Program,
dryRun: boolean = false,
options: Polkadot.Options = defaultOptions
options: Polkadot.Options = defaultOptions,
verbose: boolean = false,
): Promise<Process.Result> => {
try {

Expand All @@ -84,6 +115,7 @@ export const createProcess = async (
process,
}
}


if (dryRun)
return {
Expand All @@ -96,14 +128,16 @@ export const createProcess = async (

return {
message: `Transaction for new process ${name} has been successfully submitted`,
process: await createProcessTransaction(polkadot, processId, program, options),
process: await createProcessTransaction(polkadot, processId, program, options, verbose),
}
} catch (err) {
// err is basically from errors.ts or any exception
// process errors will comntain specific messages and/or process
// Promise<Process.Result> is in try {} and any exception is in catch {}
return err
}


}

export const disableProcess = async (
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ declare namespace Process {
port: string
user: string
host: string
verbose?: boolean
}
export type CLIParsed = Core[]
export type Program = ProgramStep[]
Expand Down