0.0.2 • Published 4 years ago

fs-read-write v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Introduction

Modular typescript CLI builder

Why to have another cli parser when we have yargs, oclif and so on.

  1. Modularity
    const base = baseCommand()
    .flag(['--debug', '-d'])
    .parse((match)=>{
        return {
            debug: match('--debug', (v) => !!v, false)
        }
    })


    const buildBase = base
    .flag('--port')
    .flag('--env')
    .parse(async (match, prev)=> {
        return {
            ...prev,
            env: await match('--env', Prompt.select('Please select environment', ['production', 'development']), 'development')
            port: await match('--port', Prompt.number('Please enter port number'), 3000)
        }
    })

    cli({
        cliName: 'pkg',
        commands: [
            base.command('lint').handle(()=> {
                // Handle lint
                 }),
                 buildBase.command('watch').handle(({ debug, env, port })=>{
        // handle watch command
    }),     buildBase.command('build').handle(({ debug, env, port })=>{
        // handle watch command
    })
        ]
    })
  1. Arguments validation order
  2. Arguments dependencies

    Let's assume simple cli yarn xxx --namespace abc --customer sample

    • Customer value depends on namespace
    1. Let's assume that abc namespace is invalid and correct namespace is abc_123

    Cli should fail