Skip to content

Commit

Permalink
CLI helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-marky committed Sep 4, 2023
1 parent f70ca9a commit 343df90
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Command } from 'commander'
import { loadProcesses, disableProcess } 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 @@ -57,31 +59,9 @@ program
`)
try {
const res: Process.RawPayload[] = await getAll(mapOptions(options))
const { raw, active, disabled } = options
let processes: Process.RawPayload[]
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,
...options.verbose ? { program: p.program } : { }
}
}),
{ depth: null }
)
}

listHelper(res, processes, options)

process.exit(0)
} catch (err) {
Expand Down
26 changes: 26 additions & 0 deletions src/lib/utils/cliHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const listHelper = 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 }
)
}
}

0 comments on commit 343df90

Please sign in to comment.