@richardo2016/rcli
Version:
Richard's cli
134 lines (118 loc) • 3.62 kB
JavaScript
#!/usr/bin/env fibjs
const pkg = require('../package.json')
const cli = require('@fxjs/cli')()
const cwd = process.cwd()
cli
.command('[nothing]', 'empty')
.action(() => {
})
const cmd2gif = require('../lib/command-2gif').default
;[
cli.command('2gif <entry> [target_dir]', 'transform non-gif image to gif'),
cli.command('image <entry> [target]', 'transform image to target'),
].forEach(cmd => {
cmd
.option('-o, --out [targetfile]', 'target' , {
type: String
})
.option('-z, --comparesion-rate [compression_rate]', 'compression rate', {
type: Number,
default: 1
})
.action((entry, target, options) => {
const srcfile = entry || './'
target = target || options.out
cmd2gif(srcfile, target, {
cwd: cwd,
compression_rate: options.z
})
})
})
const cmdZip = require('../lib/command-zip').default
cli
.command('zip <entry> [target_zip]', 'zip directory or file')
.option('-o, --out [targetfile]', 'target' , {
type: String
})
.option('-p, --password [password]', 'zip password', {
type: String,
default: ''
})
.action((entry, target_zip, options) => {
const srcfile = entry || './'
target_zip = target_zip || options.out
cmdZip(srcfile, target_zip, {
cwd: cwd,
password: options.p
})
})
const {default: cmdYaml2json, JSYAML_SCHEMAS_ABBR} = require('../lib/command-yaml2js')
cli
.command('yaml2js <srcfile>', 'transform yaml to json', {
allowUnknownOptions: true
})
.option('-o, --out <targetfile>', 'target' , {
type: 'string'
})
.option('-s, --safe', 'safe mode' , {
default: true
})
.option('-j, --json', 'export as json' , {
default: false,
})
.option('-m, --multiple', 'if multiple line' , {
default: false
})
.option('-S, --schema [schema]', `schema: ${Object.keys(JSYAML_SCHEMAS_ABBR).join(' | ')}` , {
type: String,
default: JSYAML_SCHEMAS_ABBR.CORE
})
.action((srcfile, options) => {
let targetfile = options.out
if (process.env.DEBUG) {
console.log('srcfile', srcfile);
console.log('targetfile', targetfile);
console.log('options', options);
}
cmdYaml2json(srcfile, targetfile, {
cwd: cwd,
safe: options.safe,
schema: options.schema,
json: options.json,
multiple: options.multiple
})
})
cli
.command('orm [...args]', 'manager your db by orm', {
allowUnknownOptions: true
})
.option('-d, --dir [dir]', 'context directory' , {
default: process.cwd(),
type: 'string'
})
.option('--orm-entry [ormentry]', 'orm definitions entry file' , {
default: undefined,
type: 'string'
})
.option('--http-method [method]', 'orm definitions entry file' , {
default: 'GET',
type: 'string'
})
.option('--connection [connection]', 'orm definitions entry file' , {
default: undefined,
type: 'string'
})
.action((args, options) => {
const {default: cmd_orm} = require('../lib/command-orm')
const [ url = '' ] = args || []
const {
dir = process.cwd(),
ormEntry = './orm-defs',
httpMethod = 'GET',
connection
} = options;
cmd_orm(url, { dir, ormEntry, httpMethod, connection });
})
cli.help()
cli.version(pkg.version)
cli.parse()