How to use string-argv - 10 common examples

To help you get started, we’ve selected a few string-argv 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 HcashOrg / hcGUI / app / main.development.js View on Github external
const util = require("util");
      const win32ipc = require("./node_modules/win32ipc/build/Release/win32ipc.node");
      var pipe = win32ipc.createPipe("out");
      console.log(pipe.readEnd)
      args.push(util.format("--piperx=%d", pipe.readEnd));
    } catch (e) {
      logger.log("error", "can't find proper module to launch hcwallet: " + e);
    }
  } else {
    args.push("--rpclistenerevents");
    args.push("--pipetx=4");
  }

  // Add any extra args if defined.
  if (argv.extrawalletargs !== undefined && isString(argv.extrawalletargs)) {
    args = concat(args, stringArgv(argv.extrawalletargs));
  }

  logger.log("info", `Starting ${hcwExe} with ${args}`);

  var hcwallet = spawn(hcwExe, args, {
    detached: os.platform() == "win32",
    stdio: ["ignore", "pipe", "pipe", "ignore", "pipe"]
  });

  const notifyGrpcPort = (port) => {
    hcwPort = port;
    logger.log("info", "wallet grpc running on port", port);
    mainWindow.webContents.send("hcwallet-port", port);
  };

  hcwallet.stdio[4].on("data", (data) => DecodeDaemonIPCData(data, (mtype, payload) => {
github okonet / lint-staged / src / resolveTaskFn.js View on Github external
} else if (/^git(\.exe)?/i.test(linter) && gitDir !== process.cwd()) {
    // Only use gitDir as CWD if we are using the git binary
    // e.g `npm` should run tasks in the actual CWD
    execaOptions.cwd = gitDir
  }

  let cmd
  let args

  if (shell) {
    execaOptions.shell = true
    // If `shell`, passed command shouldn't be parsed
    // If `linter` is a function, command already includes `pathsToLint`.
    cmd = isFn ? linter : `${linter} ${pathsToLint.join(' ')}`
  } else {
    const [parsedCmd, ...parsedArgs] = stringArgv.parseArgsStringToArgv(linter)
    cmd = parsedCmd
    args = isFn ? parsedArgs : parsedArgs.concat(pathsToLint)
  }

  return ctx =>
    execLinter(cmd, args, execaOptions).then(result => {
      if (result.failed || result.killed || result.signal != null) {
        throw makeErr(linter, result, ctx)
      }

      return successMsg(linter)
    })
}
github cucumber / cucumber-js / features / step_definitions / cli_steps.js View on Github external
function(args) {
    if (!args) {
      args = ''
    }
    // message is always outputted as part of run
    const formats = ['json:json.out']
    args += ' ' + formats.map(f => `--format ${f}`).join(' ')
    args = Mustache.render(args, this)
    args = stringArgv(args)
    return this.run(this.localExecutablePath, args)
  }
)
github hkwu / ghastly / src / command / parsers / ParameterParser.js View on Github external
parsed.defaultValue = [];
    } else if (name.endsWith('...')) {
      if (parsed.type !== STRING) {
        throw new ParameterParserError(`Literals can only be used with string parameters: '${definition}'.`);
      }

      parsed.name = trimEnd(name, '. ');
      parsed.literal = true;
    } else if (name.includes(' ')) {
      throw new ParameterParserError(`Parameter name must not contain spaces: '${definition}'.`);
    } else {
      parsed.name = name;
    }

    if (matched) {
      const defaults = stringArgv(matched[2]);
      // default value automatically makes it optional
      parsed.optional = true;

      if (!parsed.repeatable && defaults.length > 1) {
        throw new ParameterParserError(`Cannot provide more than one default argument for non-repeatable parameters: '${definition}'.`);
      }

      const typedDefaults = defaults.map((value) => {
        if (!isType(value, parsed.type)) {
          throw new ParameterParserError(`Given default value '${value}' is not of the correct type: '${definition}'.`);
        }

        return convertType(value, parsed.type);
      });

      parsed.defaultValue = parsed.repeatable ? typedDefaults : typedDefaults[0];
github chanzo / script-launcher / src / executor.ts View on Github external
private static getCommandInfo(command: string, options: ISpawnOptions): { command: string, args: string[], options: ISpawnOptions } {
    if (!command) command = '';

    options = { ...options };
    options.env = { ...options.env };

    command = Executor.expandEnvironment(command, options.env);

    if (!options.cwd) options.cwd = '';

    let args = [];

    if (!options.shell) {
      args = parseArgsStringToArgv(command);
      command = args[0];
      args.shift();
    }

    if (command === '') {
      console.log();

      return { command: null, args, options };
    }

    if (command === 'echo') {
      if (process.platform === 'win32') command += '.';

      return { command, args, options };
    }
github actions-rs / grcov / src / configuration.ts View on Github external
function loadInputs(): Input {
    if (!process.env.GITHUB_WORKSPACE) {
        throw new Error('Environment variable GITHUB_WORKSPACE is undefined. \
Did you forgot to checkout the code first?');
    }

    let inputs: Input = {
        testArgs: ['test'].concat(stringArgv(input.getInput('args'))),
    };

    const relConfigPath = input.getInput('config');
    if (relConfigPath.length > 0) {
        inputs.configPath = path.join(
            process.env.GITHUB_WORKSPACE!,
            relConfigPath,
        );
    } else {
        inputs.configPath = path.join(
            process.env.GITHUB_WORKSPACE!,
            DEFAULT_CONFIG_PATH,
        )
    }

    return inputs;
github hkwu / ghastly / src / parsers / SignatureParser.js View on Github external
const { value: type, ...rest } = SignatureParser.parseTokenModifiers(modifiers);

      if (!Constants.TOKEN.TYPE[type]) {
        throw new SignatureParserError(`<${type}> is not a valid parameter type. Given parameter: <[${parameter}]>.`);
      }

      token = { ...token, ...rest, type: Constants.TOKEN.TYPE[type] };
      signature = signatureAndType[1].trim();
    } else {
      const { value, ...rest } = SignatureParser.parseTokenModifiers(signature);
      token = { ...token, ...rest };
      signature = value;
    }

    if (token.arity === Constants.TOKEN.ARITY.VARIADIC) {
      token.defaultValue = token.defaultValue ? stringArgv(token.defaultValue) : [];
    }

    if (token.defaultValue && token.type !== Constants.TOKEN.TYPE.STRING) {
      const typeValidator = (value) => {
        if (!Constants.TYPE_CHECKERS[token.type](value)) {
          throw new SignatureParserError(`Expected default value <${value}> to be of type <${token.type}>. Given parameter: <[${parameter}]>.`);
        }

        return value;
      };

      if (token.arity === Constants.TOKEN.ARITY.UNARY) {
        token.defaultValue = Constants.TYPE_CONVERTERS[token.type](typeValidator(token.defaultValue));
      } else {
        token.defaultValue = token.defaultValue.map(value => (
          Constants.TYPE_CONVERTERS[token.type](typeValidator(value))
github nrkno / tv-automation-casparcg-launcher / src / main / process.js View on Github external
try {
      const exeStat = fs.statSync(procPath)
      fileExists = exeStat.isFile()
    } catch (e) {
      fileExists = false
    }
    if (!fileExists) {
      log.info('[' + this.id + '] Executable does not exist: ' + procPath)
      this.pipeLog('event', '== Executable does not exist ==')
      this.pipeStatus('failed')
      return
    }

    const args = this.config.args || ''
    this.process = respawn(
      [this.config.exeName].concat(stringArgv(args)), {
        cwd: basePath
      }
    )

    this.process.on('start', () => {
      if (this.healthMon) {
        this.healthMon.start()
      }

      this.restarting = false
      log.info('[' + this.id + '] ' + this.config.exeName + ' start')
      this.pipeLog('event', '== Process has started ==')
      this.pipeStatus('running')
    })
    this.process.on('stdout', (data) => {
      this.pipeLog('log', data)
github Gawdl3y / discord-rpbot / src / commands / dispatcher.js View on Github external
export function matchDefault(message, pattern, commandNameIndex = 1) {
	const matches = pattern.exec(message.content);
	if(matches) {
		const commandName = matches[commandNameIndex].toLowerCase();
		const command = commands.find(cmd => cmd.name === commandName || (cmd.aliases && cmd.aliases.some(alias => alias === commandName)));
		if(command && !command.disableDefault) {
			const argString = message.content.substring(matches[1].length + (matches[2] ? matches[2].length : 0));
			return [command, !command.singleArgument ? stringArgv(argString) : [argString.trim()]];
		}
		return [null, null, true];
	}
	return [null, null, false];
}
github hkwu / ghastly / src / Commands / CommandHandler.js View on Github external
}
      }
    }

    if (!handler) {
      return false;
    }

    if (parsed.mentioned && handler.mentionable === MENTIONABLE_DENY) {
      return false;
    } else if (!parsed.mentioned && handler.mentionable === MENTIONABLE_ONLY) {
      return false;
    }

    try {
      const commandArgs = ArgumentParser.parse(handler.parameters, stringArgv(args.join(' ')));
      handler.action(message, commandArgs);

      return true;
    } catch (error) {
      handler.onBadArgs(message);

      return false;
    }
  }
}

string-argv

string-argv parses a string into an argument array to mimic process.argv. This is useful when testing Command Line Utilities that you want to pass arguments to.

MIT
Latest version published 12 months ago

Package Health Score

74 / 100
Full package analysis

Popular string-argv functions