How to use command-line-args - 10 common examples

To help you get started, we’ve selected a few command-line-args 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 preciousforever / data-populator / source / core / library / args.js View on Github external
export function parseArgs (string, definitions) {

  // parse args using the provided definitions
  return commandLineArgs(definitions, string.split(/\s+/g))
}
github debitoor / nocms / packages / nocms / src / bin / nocms-worker.js View on Github external
const optionDefinitions = [
			{ name: 'help', alias: 'h' },
			{ name: 'in-dir', alias: 'i', type: String, description: 'Input directory to read resources from.' },
			{ name: 'out-dir', alias: 'o', type: String, description: 'Output directory to write compiled resource to.' }
		];

		const usageDefinition = [
			{ header: 'NOCMS Worker Process Command Line Interface', content: nocmsAscii, raw: true },
			{ header: 'Synopsis', content: '$ nocms-worker ' },
			{ header: 'Options', optionList: optionDefinitions }
		];

		let options;

		try {
			options = commandLineArgs(optionDefinitions);
		} catch (err) {
			options = { help: true };
		}

		if (options.help) {
			const usage = commandLineUsage(usageDefinition);
			console.log(usage);
			return;
		}

		const inDir = options['in-dir'];
		const outDir = options['out-dir'];

		// Load config rc file
		const config = await loadConfig(inDir);
github seanpmaxwell / express-generator-typescript / sample-output / express-gen-ts / spec / index.ts View on Github external
import find from 'find';
import Jasmine from 'jasmine';
import dotenv from 'dotenv';
import commandLineArgs from 'command-line-args';
import { logger } from '@shared';

// Setup command line options
const options = commandLineArgs([
    {
        name: 'testFile',
        alias: 'f',
        type: String,
    },
]);

// Set the env file
const result2 = dotenv.config({
    path: `./env/test.env`,
});
if (result2.error) {
    throw result2.error;
}

// Init Jasmine
github cosmos / gravity-bridge / solidity / contract-deployer.ts View on Github external
import { Peggy } from "./typechain/Peggy";
import { TestERC20A } from "./typechain/TestERC20A";
import { TestERC20B } from "./typechain/TestERC20B";
import { TestERC20C } from "./typechain/TestERC20C";
import { TestUniswapLiquidity } from "./typechain/TestUniswapLiquidity";
import { ethers } from "ethers";
import fs from "fs";
import commandLineArgs from "command-line-args";
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
import { exit } from "process";

const args = commandLineArgs([
  // the ethernum node used to deploy the contract
  { name: "eth-node", type: String },
  // the cosmos node that will be used to grab the validator set via RPC (TODO),
  { name: "cosmos-node", type: String },
  // the Ethereum private key that will contain the gas required to pay for the contact deployment
  { name: "eth-privkey", type: String },
  // the peggy contract .json file
  { name: "contract", type: String },
  // test mode, if enabled this script deploys three ERC20 contracts for testing
  { name: "test-mode", type: String },
]);

// 4. Now, the deployer script hits a full node api, gets the Eth signatures of the valset from the latest block, and deploys the Ethereum contract.
//     - We will consider the scenario that many deployers deploy many valid peggy eth contracts.
// 5. The deployer submits the address of the peggy contract that it deployed to Ethereum.
//     - The peggy module checks the Ethereum chain for each submitted address, and makes sure that the peggy contract at that address is using the correct source code, and has the correct validator set.
github LedgerHQ / ledger-live-common / cli / src / cli.js View on Github external
console.log("                    :::::::-.`          ");
  console.log("                    ....``              ");
  console.log("");
  console.log(
    "Please be advised this software is experimental and shall not create any obligation for Ledger to continue to develop, offer, support or repair any of its features. The software is provided “as is.” Ledger shall not be liable for any damages whatsoever including loss of profits or data, business interruption arising from using the software."
  );
  process.exit(0);
}

const cmd = commands[mainOptions.command];
if (!cmd) {
  console.error("Command not found: ledger-live " + mainOptions.command);
  process.exit(1);
}
const argv = mainOptions._unknown || [];
const options = commandLineArgs(cmd.args, { argv });
from(cmd.job(options)).subscribe({
  next: log => {
    if (log !== undefined) console.log(log);
  },
  error: error => {
    const e = error instanceof Error ? error : deserializeError(error);
    if (process.env.VERBOSE || process.env.VERBOSE_FILE) console.error(e);
    else console.error(String(e.message || e));
    process.exit(1);
  },
  complete: () => {
    closeAllDevices();
  }
});
github luk707 / envup / envup / src / index.js View on Github external
},
      {
        name: "help",
        description: "Display this usage guide.",
        alias: "h",
        type: Boolean,
        group: "main"
      }
    ]
  },
  {
    content: "Github: [underline]{https://github.com/luk707/envup}"
  }
]);

const options = commandLineArgs(optionDefinitions);

const { help, directory } = options;

if (help) {
  console.log(usage);
  process.exit(0);
}

const readEnvFile = (path, options) =>
  new Promise((resolve, reject) => {
    if (options.skip) {
      resolve({});
    }
    fs.exists(path).then(envFileExists => {
      if (envFileExists) {
        resolve(
github google / chicago-brick / server / server.js View on Github external
{name: 'port', type: Number, defaultValue: 3000},
  {name: 'use_geometry', type: JSON.parse, defaultValue: null},
  {name: 'screen_width', type: Number, defaultValue: 1920},
  {name: 'layout_duration', type: Number},
  {name: 'module_duration', type: Number},
  {name: 'max_partitions', type: Number},
  {name: 'game_server_host', type: String, defaultValue: ''},
  {name: 'geometry_file', type: String},
  {name: 'credential_dir', type: String},
  {name: 'enable_monitoring', type: Boolean},
  {name: 'use_https', type: Boolean, defaultValue: false,
    description: 'Enables HTTPS. Certificates must exist in certs/.'},
  {name: 'require_client_cert', type: Boolean, defaultValue: false,
    description: 'Whether to require HTTPS certs from clients.'}
];
let flags = commandLineArgs(FLAG_DEFS);
if (flags.help) {
  console.log('Available flags: ' + commandLineUsage({optionList: FLAG_DEFS}));
  process.exit();
}
log('flags')
log(flags);
if (flags.use_geometry) {
  wallGeometry.useGeo(flags.use_geometry);
} else if (flags.geometry_file) {
  wallGeometry.useGeo(wallGeometry.loadGeometry(flags.geometry_file));
} else {
  console.log('No wall geometry specified... assuming 1x1.');
  wallGeometry.useGeo([{"right":1},{"down":1},{"left":1},{"up":1}]);
}

if (flags.screen_width) {
github develar / onshape-desktop-shell / build / build.js View on Github external
"use strict"

const fs = require("fs")
const path = require("path")
const util = require("./util")

const args = require("command-line-args")([
  {name: "build", type: Boolean, defaultValue: false},
  {name: "sign", type: String},
  {name: "platform", type: String, defaultValue: process.platform},
  {name: "arch", type: String, defaultValue: "all"},
]).parse()

let outDir = path.join(__dirname, "/../dist") + "/"
const isMacBuild = args.platform === "darwin"
if (isMacBuild) {
  outDir += "Onshape-darwin-x64"
}
else {
  outDir += "win"
}
outDir = path.normalize(outDir)
console.log("Removing " + outDir)
github LedgerHQ / ledgerjs / packages / hw-http-proxy-devserver / src / cmd.js View on Github external
import {
  RecordStore,
  createTransportRecorder,
  createTransportReplayer
} from "@ledgerhq/hw-transport-mocker";
import commandLineArgs from "command-line-args";
import fs from "fs";
import http from "http";
import express from "express";
import cors from "cors";
import WebSocket from "ws";
import bodyParser from "body-parser";
import os from "os";

const mainOptions = commandLineArgs([
  {
    name: "file",
    alias: "f",
    type: String
  },
  {
    name: "silent",
    alias: "s",
    type: Boolean
  }
]);

let Transport;
let saveToFile = null;
let recordStore;
github sharvit / mongoose-data-seed / src / lib / commands / generate / options.js View on Github external
export const getOptions = argv => {
  const {
    name: seederName,
    help: helpWanted,
  } = commandLineArgs(optionDefinitions, { argv });

  const options = { seederName, helpWanted };

  validateOptions(options);

  return options;
};

command-line-args

A mature, feature-complete library to parse command-line options.

MIT
Latest version published 2 months ago

Package Health Score

83 / 100
Full package analysis

Popular command-line-args functions