How to use args - 10 common examples

To help you get started, we’ve selected a few 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 leo / cory / bin / build.js View on Github external
import path from 'path'

// Packages
import args from 'args'
import chalk from 'chalk'
import chokidar from 'chokidar'
import walk from 'walk'
import ncp from 'ncp'
import broccoli from 'broccoli'

// Ours
import config from '../lib/config'
import {isSite as exists} from '../lib/etc'
import {compile} from '../lib/compiler'

args.option('watch', 'Rebuild site if files change')
const options = args.parse(process.argv)

if (!exists()) {
  console.error(chalk.red('No site in here!'))
  process.exit(1)
}

const timerStart = new Date().getTime()

const walker = walk.walk(process.cwd(), {
  filters: [
    /\b(layouts)\b/,
    /\b(dist)\b/,
    /\b(tmp)\b/,
    /\b(node_modules)\b/,
    path.parse(config.assetDir).base
github mfix22 / gest / bin / gest.js View on Github external
.then(() => console.log())
      .catch((/* err */) => {
        console.log('\n' + errors)
        process.exit(1)
      })
  } else {
    if (flags.print) {
      const q = args.sub[0] || flags.print
      return wrapLogging(
        getQueryString(q)
          .then(GraphQL.parse)
          .then(GraphQL.print)
      )
    }
    if (args.sub && args.sub.length) {
      args.sub.map(q =>
        wrapLogging(
          getQueryString(q)
            .then(gest(schema, options))
            .then(res => {
              const message = colorResponse(res) + '\n'
              if (res.errors) {
                throw '\n' + message
              }
              return message
            })
        )
      )
    } else {
      // Open REPL
      REPL(schema, options)
    }
github mfix22 / gest / bin / gest.js View on Github external
.then(tasks => tasks.run())
      .then(() => console.log())
      .catch((/* err */) => {
        console.log('\n' + errors)
        process.exit(1)
      })
  } else {
    if (flags.print) {
      const q = args.sub[0] || flags.print
      return wrapLogging(
        getQueryString(q)
          .then(GraphQL.parse)
          .then(GraphQL.print)
      )
    }
    if (args.sub && args.sub.length) {
      args.sub.map(q =>
        wrapLogging(
          getQueryString(q)
            .then(gest(schema, options))
            .then(res => {
              const message = colorResponse(res) + '\n'
              if (res.errors) {
                throw '\n' + message
              }
              return message
            })
        )
      )
    } else {
      // Open REPL
      REPL(schema, options)
github jaretburkett / electron-icon-maker / index.js View on Github external
#!/usr/bin/env node

const Jimp = require("jimp");
const args = require('args');
const path = require('path');
const fs = require('fs');
const icongen = require( 'icon-gen' );

var pngSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024];

args
    .option('input', 'Input PNG file. Recommended (1024x1024)', './icon.png')
    .option('output', 'Folder to output new icons folder', './');

const flags = args.parse(process.argv);
console.log(flags);

// correct paths
var input = path.resolve(process.cwd(), flags.input);
var output = path.resolve(process.cwd(), flags.output);
var o = output;
var oSub = o.endsWith('/') ? o + 'icons/' : o + '/icons/';
var PNGoutputDir = oSub + 'png/';

const iconOptions = {
    type: 'png',
    report: true
};

// do it
createPNGs(0);
github T-Specht / ts-typie / app.ts View on Github external
// look for the first available tool
let defaultTool;
for (const tool of Object.keys(tools)) {
    if (commandExists.sync(tool)) {
        defaultTool = tool;
        break;
    }
}
if (defaultTool === undefined) {
    console.error('Couldn\'t find a supported package manager tool.')
}

// support for overriding default
args.option('tool', 'Which package manager tool to use', defaultTool);
const opts = args.parse(process.argv, {
    name: 'ts-typie',
    mri: undefined,
    mainColor: 'yellow',
    subColor: 'dim'
});
const tool = tools[opts.tool];



// check if package.json exists

const cwd = process.cwd();
const packagePath = path.join(cwd, 'package.json');

if (!fs.existsSync(packagePath)) {
    console.error('No package.json file found!');
github xiaodoudou / PlexIPTV / index.js View on Github external
args
  .option('logdir', 'The path where the log files will be written', _.get(process, 'env.PLEXIPTV_LOGDIR', path.join(process.cwd(), 'logs')))
  .option('settings ', 'Path of the configuration file', _.get(process, 'env.PLEXIPTV_SETTINGS', path.join(process.cwd(), 'settings.json')))

const express = require('express')
const Q = require('q')
const request = require('request')
const fs = require('fs')
const validUrl = require('valid-url')
const Preloader = require('./preloader')
const DVR = require('./dvr')
const Config = require('./config')
const Logger = new (require('./logger'))()
const packageJson = require('./package.json')
const flags = args.parse(process.argv)

class Server {
  constructor () {
    this.express = express()
    this.preloader = new Preloader()
    this.config = new Config()
    this.channels = []

    // Bindings
    this.pullPlaylist = this.pullPlaylist.bind(this)
    this.readPlaylist = this.readPlaylist.bind(this)
    this.proxy = this.proxy.bind(this)
  }

  init () {
    this.config.init().then(settings => {
github axiom-org / axiom / ts / src / node / hserver-main.ts View on Github external
// This is the entry point for the hosting server.

import * as http from "http";
import * as os from "os";
import * as path from "path";

import args from "args";
import * as diskusage from "diskusage";

import NetworkConfig from "../iso/NetworkConfig";
import Node from "../iso/Node";
import PeerServer from "./PeerServer";
import { loadKeyPair } from "./FileUtil";

args
  .option("port", "The port on which the bootstrapper will be running", 3500)
  .option("keypair", "File containing keys", "")
  .option("network", "Which network to connect to", "local")
  .option(
    "directory",
    "The directory to store files in",
    path.join(os.homedir(), "hostfiles")
  );

const flags = args.parse(process.argv);

process.on("warning", e => console.warn(e.stack));

// Just for logging, check how much available disk space there is
try {
  let info = diskusage.checkSync(flags.directory);
github hammerframework / hammer / packages / hammer-dev-server / src / main.ts View on Github external
import chokidar from 'chokidar'
// @ts-ignore
import babelRegister from '@babel/register'

const hammerConfig = getHammerConfig()
const hammerApiDir = path.join(hammerConfig.baseDir, 'api')

babelRegister({
  extends: path.join(hammerApiDir, '.babelrc.js'),
  extensions: ['.js', '.ts'],
  only: [hammerApiDir],
  ignore: ['node_modules'],
})

// TODO: Convert to yargs.
args
  .option('port', '', hammerConfig.api.port)
  .option(
    'path',
    'The path to your lambda functions',
    hammerConfig.api.paths.functions
  )
const { port: PORT, path: PATH } = args.parse(process.argv)
const HOSTNAME = `http://localhost:${PORT}`

const showHeader = (lambdas: Record) => {
  console.log(`\n⚒ HammerFramework's API Development Server\n`)
  console.log(`◌ Listening on ${HOSTNAME}`)
  console.log(`◌ Watching ${hammerApiDir}`)
  console.log('\nNow serving\n')
  console.log(
    Object.keys(lambdas)
github zeit / release / bin / release.js View on Github external
);
	process.exit(1);
}

args.option('pre', 'Mark the release as prerelease')
	.option('overwrite', 'If the release already exists, replace it')
	.option('publish', 'Instead of creating a draft, publish the release')
	.option(['H', 'hook'], 'Specify a custom file to pipe releases through')
	.option(['t', 'previous-tag'], 'Specify previous release', '')
	.option(['u', 'show-url'], 'Show the release URL instead of opening it in the browser');

const flags = args.parse(process.argv);

// When running `release pre`, the release
// should automatically be marked as a pre-release
if (args.sub[0] === 'pre') {
	flags.pre = true;
}

let githubConnection;
let repoDetails;

const changeTypes = [
	{
		handle: 'major',
		name: 'Major Change',
		pluralName: 'Major Changes',
		description: 'incompatible API change'
	},
	{
		handle: 'minor',
		name: 'Minor Change',
github zeit / release / bin / release.js View on Github external
#!/usr/bin/env node --harmony-async-await

// Packages
const args = require('args')

// Utilities
const validateProject = require('../utils/validate')

args.parse(process.argv)

// Make sure that the project is ready for releases
// If it's not, throw errors to indicate the exact problem
validateProject(args.sub)

const releaseType = args.sub[0]
console.log(releaseType)