How to use clap - 10 common examples

To help you get started, we’ve selected a few clap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github basisjs / basisjs-tools / lib / create / command.js View on Github external
default:
      options.output = path.resolve(options.output);
  }
  options.outputDir = path.normalize(options.output);

  // resolve input dir
  options.templates = (options.templates || [])
    .concat(__dirname + '/template/')
    .map(function(dir){
      return path.resolve(options._configPath || options.base, dir);
    });

  return options;
}

var command = clap.create('create')
  .description('Code generator')
  .option('-b, --base 
github basisjs / basisjs-tools / lib / create / index.js View on Github external
//

  var target;
  var output = [];

  switch (topic)
  {
    case 'app':
    case 'module':
      target = topic == 'app' ? options.output : path.join(options.output, options.name);
      resolveDirPath(target);
      output = [target];

      // if folder exists and not empty - confirm possible file rewrite
      if (fs.readdirSync(target).length)
        clap.confirm('Destination folder is not empty, some files may be overwritten. Continue? (y/n) ', function(yes){
          if (yes)
          {
            console.log();
            mainTask();
          }
        });
      else
        mainTask();

      break;

    case 'type':
      options.instanceName = options.name.charAt(0).toLowerCase() + options.name.substr(1);
      target = options.output;
      output = [target];
github basisjs / basisjs-tools / bin / basis.js View on Github external
{
    var cfgFile = curpath.join(path.sep) + path.sep + 'basis.config';

    if (fs.existsSync(cfgFile))
      return fetchConfig(cfgFile);

    curpath.pop();
  }
}


//
// main part
//

var program = cli.create('basis')
  .version(require('../package.json').version)
  .option('-n, --no-config', 'Don\'t use basis.config')
  .option('-c, --config-file ', 'Specify path to config filename')
  .delegate(function(nextCommand){
    var options = this.values;
    if (options.config && nextCommand.name != 'completion')
    {
      var config = options.configFile
        ? fetchConfig(options.configFile)
        : searchConfig();

      if (config)
      {
        nextCommand.config = config.data;
        nextCommand.configFile = config.filename;
        nextCommand.configPath = config.path;
github aemoe / webpack-react-framework / node_modules / csso / lib / cli.js View on Github external
}

    // source map placed in external file
    if (inputMapFile) {
        inputMapContent = fs.readFileSync(inputMapFile, 'utf8');
    }

    return {
        input: inputMapContent,
        inputFile: inputMapFile || (inputMapContent ? '' : false),
        output: map,
        outputFile: outputMapFile
    };
}

var command = cli.create('csso', '[input] [output]')
    .version(require('../package.json').version)
    .option('-i, --input ', 'Input file')
    .option('-o, --output ', 'Output file (result outputs to stdout if not set)')
    .option('-m, --map ', 'Generate source map: none (default), inline, file or ', 'none')
    .option('-u, --usage ', 'Usage data file')
    .option('--input-map <source>', 'Input source map: none, auto (default) or ', 'auto')
    .option('--restructure-off', 'Turns structure minimization off')
    .option('--stat', 'Output statistics in stderr')
    .option('--debug [level]', 'Output intermediate state of CSS during compression', debugLevel, 0)
    .action(function(args) {
        var options = this.values;
        var inputFile = options.input || args[0];
        var outputFile = options.output || args[1];
        var usageFile = options.usage;
        var usageData = false;
        var map = options.map;
github css / csso / lib / cli.js View on Github external
};
}

function processCommentsOption(value) {
    switch (value) {
        case 'exclamation':
        case 'first-exclamation':
        case 'none':
            return value;
    }

    console.error('Wrong value for `comments` option: %s', value);
    process.exit(2);
}

var command = cli.create('csso', '[input] [output]')
    .version(require('../package.json').version)
    .option('-i, --input ', 'Input file')
    .option('-o, --output ', 'Output file (result outputs to stdout if not set)')
    .option('-m, --map ', 'Generate source map: none (default), inline, file or ', 'none')
    .option('-u, --usage ', 'Usage data file')
    .option('--input-map <source>', 'Input source map: none, auto (default) or ', 'auto')
    .option('--restructure-off', 'Turns structure minimization off')
    .option('--comments ', 'Comments to keep: exclamation (default), first-exclamation or none', 'exclamation')
    .option('--stat', 'Output statistics in stderr')
    .option('--debug [level]', 'Output intermediate state of CSS during compression', debugLevel, 0)
    .action(function(args) {
        var options = this.values;
        var inputFile = options.input || args[0];
        var outputFile = options.output || args[1];
        var usageFile = options.usage;
        var usageData = false;
github basisjs / basisjs-tools / lib / extract / command.js View on Github external
handlerList = [handlerList];
      else
        handlerList = [];

      options.preprocess[type] = handlerList;
    }

    options.preprocess[type] = handlerList.map(function(fn){
      return path.normalize(path.resolve(this.context.configPath || '.', fn));
    }, this);
  }

  return options;
}

module.exports = clap.create('extract', '[file]')
  .description('Extract file graph')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);
    if (config)
      applyConfig(this, config.data['build'] || {}, config.path);
  })

  .option('-b, --base 
github basisjs / basisjs-tools / lib / lint / command.js View on Github external
handlerList = [handlerList];
      else
        handlerList = [];

      options.preprocess[type] = handlerList;
    }

    options.preprocess[type] = handlerList.map(function(fn){
      return path.normalize(path.resolve(module.exports._configPath || '.', fn));
    });
  }

  return options;
}

module.exports = clap.create('lint', '[file]')
  .description('Lint files')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);
    if (config)
      applyConfig(this, config.data['build'] || {}, config.path);
  })

  .option('-b, --base 
github basisjs / basisjs-tools / lib / server / command.js View on Github external
config.ignore = Array.isArray(config.ignore)
        ? config.ignore.map(function(fileMask){
            return options.configPath_ ? path.resolve(options.configPath_, fileMask) : fileMask;
          })
        : false;

    config.name = config.name || config.filename;
    config.filename = resolve.sync(config.filename || config.name, { basedir: process.cwd() });

    return config;
  }).filter(Boolean);

  return options;
}

module.exports = clap.create('server')
  .description('Launch dev-server')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);

    if (config)
    {
      applyConfig(this, config.data[this.name] || {}, config.path);
      if (config.data.plugins)
      {
        this.values.plugins = config.data.plugins;
        this.values.configPath_ = config.path;
      }
    }

    if (!config || !config.editor)
github basisjs / basisjs-tools / lib / build / command.js View on Github external
}

  for (var type in configPreprocess)
    addPreprocessors(type, configPreprocess[type]);

  /*if (options.jsCutDev)
  {
    if (!options.preprocess['script'])
      options.preprocess['script'] = [];
    options.preprocess['script'].push('./misc/preprocess/js-cut-dev.js');
  }*/

  return options;
}

module.exports = clap.create('build', '[file]')
  .description('Build an app')

  .init(function(){
    var config = this.context.config = this.root.getConfig(this.values);
    if (config)
      applyConfig(this, config.data['build'] || {}, config.path);
  })
  .args(function(filename){
    this.setOption('file', filename);
  })

  .option('-b, --base 
github css / csso-cli / index.js View on Github external
if (options.statistics) {
            var timeDiff = process.hrtime(time);
            showStat(
                relInputFilename,
                source.length,
                result.css.length,
                sourceMap.inputFile,
                sourceMapAnnotation.length,
                parseInt(timeDiff[0] * 1e3 + timeDiff[1] / 1e6, 10),
                process.memoryUsage().heapUsed - mem
            );
        }
    });
}

var command = cli.create('csso', '[input]')
    .version(require('csso/package.json').version)
    .option('-i, --input ', 'Input file')
    .option('-o, --output ', 'Output file (result outputs to stdout if not set)')
    .option('-s, --source-map ', 'Generate source map: none (default), inline, file or ', 'none')
    .option('-u, --usage ', 'Usage data file')
    .option('--input-source-map <source>', 'Input source map: none, auto (default) or ', 'auto')
    .option('-d, --declaration-list', 'Treat input as a declaration list')
    .option('--no-restructure', 'Disable structural optimisations')
    .option('--force-media-merge', 'Enable unsafe merge of @media rules')
    .option('--comments ', 'Comments to keep: exclamation (default), first-exclamation or none', 'exclamation')
    .option('--stat', 'Output statistics in stderr')
    .option('--debug [level]', 'Output intermediate state of CSS during a compression', debugLevel, 0)
    .option('--watch', 'Watch source file for changes')
    .action(function(args) {
        var options = processOptions(this.values, args);

clap

Command line argument parser

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular clap functions