hana-cli
Version:
HANA Developer Command Line Interface
78 lines (71 loc) • 2.29 kB
JavaScript
// @ts-check
import * as baseLite from '../utils/base-lite.js'
import { buildDocEpilogue } from '../utils/doc-linker.js'
export const command = 'iniContents [file] [section]'
export const aliases = ['if', 'inifiles', 'ini']
export const describe = baseLite.bundle.getText("iniContents")
export const builder = (yargs) => yargs.options(baseLite.getBuilder({
file: {
alias: ['f'],
type: 'string',
default: "*",
desc: baseLite.bundle.getText("file")
},
section: {
alias: ['s'],
type: 'string',
default: "*",
desc: baseLite.bundle.getText("section")
},
limit: {
alias: ['l'],
type: 'number',
default: 200,
desc: baseLite.bundle.getText("limit")
}
})).wrap(160).example('hana-cli iniContents --file myFile', baseLite.bundle.getText("iniContentsExample")).wrap(160).epilog(buildDocEpilogue('iniContents', 'system-tools', ['iniFiles', 'config']))
export async function handler (argv) {
const base = await import('../utils/base.js')
base.promptHandler(argv, iniContents, {
file: {
description: base.bundle.getText("file"),
type: 'string',
required: true
},
section: {
description: base.bundle.getText("section"),
type: 'string',
required: true
},
limit: {
description: base.bundle.getText("limit"),
type: 'number',
required: true
}
})
}
export async function iniContents(prompts) {
const base = await import('../utils/base.js')
base.debug('iniContents')
try {
base.setPrompts(prompts)
const db = await base.createDBConnection()
prompts.limit = base.validateLimit(prompts.limit)
let iniFile = base.dbClass.objectName(prompts.file)
let section = base.dbClass.objectName(prompts.section)
var query =
`SELECT * from M_INIFILE_CONTENTS
WHERE FILE_NAME LIKE ?
AND SECTION LIKE ?
ORDER BY FILE_NAME, SECTION, KEY `
if (prompts.limit || base.sqlInjectionUtils.isAcceptableParameter(prompts.limit.toString())) {
query += `LIMIT ${prompts.limit.toString()}`
}
let results = await db.statementExecPromisified(await db.preparePromisified(query), [iniFile, section])
base.outputTableFancy(results)
base.end()
return results
} catch (error) {
await base.error(error)
}
}