How to use the string-argv.parseArgsStringToArgv function in string-argv

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 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 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 chanzo / script-launcher / src / scripts.ts View on Github external
public static parse(pattern: string): { command: string, arguments: string[] } {
    const args = parseArgsStringToArgv(pattern);

    return {
      command: args.length > 0 ? args[0] : '',
      arguments: args.slice(1),
    };
  }
github chanzo / script-launcher / src / executor.ts View on Github external
private static convertSingleQuote(command: string): string {
    const argv = parseArgsStringToArgv(command);
    const result: string[] = [];

    for (let value of argv) {
      if (value.includes(' ')) value = '"' + value + '"';

      result.push(value);
    }

    return result.join(' ');
  }
github alibaba / funcraft / lib / docker.js View on Github external
if (!imageName) {
    imageName = await dockerOpts.resolveRuntimeToDockerImage(runtime, true);
    if (!imageName) {
      throw new Error(`invalid runtime name ${runtime}`);
    }
  }

  debug(`cmd: ${parseArgsStringToArgv(cmd || '')}`);

  const container = await createContainer(dockerOpts.generateSboxOpts({
    imageName,
    hostname: `fc-${runtime}`,
    mounts,
    envs,
    cmd: parseArgsStringToArgv(cmd || ''),
    isTty,
    isInteractive
  }));

  containers.add(container.id);

  await container.start();

  const stream = await container.attach({
    logs: true,
    stream: true,
    stdin: isInteractive,
    stdout: true,
    stderr: true
  });
github logandk / serverless-rack / index.js View on Github external
);
          } else {
            return reject(res.error);
          }
        }

        if (res.status != 0) {
          return reject(res.stdout);
        }
      } else {
        this.serverless.cli.log("Packaging gem dependencies...");

        let args = ["install", "--path", "vendor/bundle"];

        if (this.bundlerArgs) {
          args.push(...stringArgv.parseArgsStringToArgv(this.bundlerArgs));
        }

        const res = child_process.spawnSync(this.bundlerBin, args);
        if (res.error) {
          if (res.error.code == "ENOENT") {
            return reject(
              `Unable to run Bundler executable: ${
                this.bundlerBin
              }. Use the "bundlerBin" option to set your Bundler executable explicitly.`
            );
          } else {
            return reject(res.error);
          }
        }

        if (res.status != 0) {
github alibaba / funcraft / lib / docker.js View on Github external
mounts, cmd, envs,
  isTty, isInteractive
}) {
  debug(`runtime: ${runtime}`);
  debug(`mounts: ${mounts}`);
  debug(`isTty: ${isTty}`);
  debug(`isInteractive: ${isInteractive}`);

  if (!imageName) {
    imageName = await dockerOpts.resolveRuntimeToDockerImage(runtime, true);
    if (!imageName) {
      throw new Error(`invalid runtime name ${runtime}`);
    }
  }

  debug(`cmd: ${parseArgsStringToArgv(cmd || '')}`);

  const container = await createContainer(dockerOpts.generateSboxOpts({
    imageName,
    hostname: `fc-${runtime}`,
    mounts,
    envs,
    cmd: parseArgsStringToArgv(cmd || ''),
    isTty,
    isInteractive
  }));

  containers.add(container.id);

  await container.start();

  const stream = await container.attach({

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 2 years ago

Package Health Score

71 / 100
Full package analysis

Popular string-argv functions