How to use the clipanion.Command.Proxy function in clipanion

To help you get started, we’ve selected a few clipanion 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 yarnpkg / berry / packages / plugin-dlx / sources / commands / dlx.ts View on Github external
import {Filename, PortablePath, npath, ppath, toFilename, xfs} from '@yarnpkg/fslib';
import {Command}                                               from 'clipanion';
import tmp                                                     from 'tmp';

// eslint-disable-next-line arca/no-default-export
export default class DlxCommand extends BaseCommand {
  @Command.String(`-p,--package`)
  pkg: string | undefined;

  @Command.Boolean(`-q,--quiet`)
  quiet: boolean = false;

  @Command.String()
  command!: string;

  @Command.Proxy()
  args: Array = [];

  static usage = Command.Usage({
    description: `run a package in a temporary environment`,
    details: `
      This command will install a package within a temporary environment, and run its binary script if it contains any. The binary will run within the current cwd.

      By default Yarn will download the package named \`command\`, but this can be changed through the use of the \`-p,--package\` flag which will instruct Yarn to still run the same command but from a different package.

      Also by default Yarn will print the full install logs when installing the given package. This behavior can be disabled by using the \`-q,--quiet\` flag which will instruct Yarn to only report critical errors.

      Using \`yarn dlx\` as a replacement of \`yarn add\` isn't recommended, as it makes your project non-deterministic (Yarn doesn't keep track of the packages installed through \`dlx\` - neither their name, nor their version).
    `,
    examples: [[
      `Use create-react-app to create a new React app`,
      `yarn dlx create-react-app ./my-app`,
github yarnpkg / berry / packages / plugin-workspace-tools / sources / commands / workspace.ts View on Github external
import {WorkspaceRequiredError}                            from "@yarnpkg/cli";
import {CommandContext, Configuration, Project, Workspace} from "@yarnpkg/core";
import {structUtils}                                       from "@yarnpkg/core";
import {Command, UsageError}                               from "clipanion";

// eslint-disable-next-line arca/no-default-export
export default class WorkspaceCommand extends Command {
  @Command.String()
  workspaceName!: string;

  @Command.String()
  commandName!: string;

  @Command.Proxy()
  args: Array = [];

  static usage = Command.Usage({
    category: `Workspace-related commands`,
    description: `run a command within the specified workspace`,
    details: `
      > In order to use this command you need to add \`@yarnpkg/plugin-workspace-tools\` to your plugins.

      This command will run a given sub-command on a single workspace.
    `,
    examples: [[
      `Add a package to a single workspace`,
      `yarn workspace components add -D react`,
    ], [
      `Run build script on a single workspace`,
      `yarn workspace components run build`,
github yarnpkg / berry / packages / plugin-essentials / sources / commands / entries / run.ts View on Github external
import {CommandContext, structUtils} from '@berry/core';
import {NodeFS, ppath}               from '@berry/fslib';
import {Command}                     from 'clipanion';

// eslint-disable-next-line arca/no-default-export
export default class EntryCommand extends Command {
  @Command.String()
  leadingArgument!: string;

  @Command.Proxy()
  args: Array = [];

  async execute() {
    if (this.leadingArgument.match(/[\\\/]/) && !structUtils.tryParseIdent(this.leadingArgument)) {
      const newCwd = ppath.resolve(this.context.cwd, NodeFS.toPortablePath(this.leadingArgument));
      return await this.cli.run(this.args, {cwd: newCwd});
    } else {
      return await this.cli.run([`run`, this.leadingArgument, ...this.args]);
    }
  }
}
github yarnpkg / berry / packages / plugin-essentials / sources / commands / node.ts View on Github external
import {BaseCommand}            from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {execUtils, scriptUtils} from '@yarnpkg/core';
import {Command}                from 'clipanion';

// eslint-disable-next-line arca/no-default-export
export default class NodeCommand extends BaseCommand {
  @Command.Proxy()
  args: Array = [];

  static usage = Command.Usage({
    description: `run node with the hook already setup`,
    details: `
      This command simply runs Node. It also makes sure to call it in a way that's compatible with the current project (for example, on PnP projects the environment will be setup in such a way that PnP will be correctly injected into the environment).

      The Node process will use the exact same version of Node as the one used to run Yarn itself, which might be a good way to ensure that your commands always use a consistent Node version.
    `,
    examples: [[
      `Run a Node script`,
      `$0 node ./my-script.js`,
    ]],
  });

  @Command.Path(`node`)
github yarnpkg / berry / packages / plugin-workspace-tools / sources / commands / foreach.ts View on Github external
const workspaceList = [];
  for (const childWorkspaceCwd of rootWorkspace.workspacesCwds) {
    const childWorkspace = project.workspacesByCwd.get(childWorkspaceCwd);
    if (childWorkspace) {
      workspaceList.push(childWorkspace, ...getWorkspaceChildrenRecursive(childWorkspace, project));
    }
  }
  return workspaceList;
};

// eslint-disable-next-line arca/no-default-export
export default class WorkspacesForeachCommand extends BaseCommand {
  @Command.String()
  commandName!: string;

  @Command.Proxy()
  args: Array = [];

  @Command.Boolean(`-a,--all`)
  all: boolean = false;

  @Command.Boolean(`-v,--verbose`)
  verbose: boolean = false;

  @Command.Boolean(`-p,--parallel`)
  parallel: boolean = false;

  @Command.Boolean(`-i,--interlaced`)
  interlaced: boolean = false;

  @Command.String(`-j,--jobs`)
  jobs?: number;
github yarnpkg / berry / packages / plugin-essentials / sources / commands / run.ts View on Github external
// what their users might have remapped them to in their `scripts` field.
  @Command.Boolean(`-B,--binaries-only`, {hidden: true})
  binariesOnly: boolean = false;

  // The v1 used to print the Yarn version header when using "yarn run", which
  // was messing with the output of things like `--version` & co. We don't do
  // this anymore, but many workflows use `yarn run --silent` to make sure that
  // they don't get this header, and it makes sense to support it as well (even
  // if it's a no-op in our case).
  @Command.Boolean(`--silent`, {hidden: true})
  silent?: boolean;

  @Command.String()
  scriptName!: string;

  @Command.Proxy()
  args: Array = [];

  static usage = Command.Usage({
    description: `run a script defined in the package.json`,
    details: `
      This command will run a tool. The exact tool that will be executed will depend on the current state of your workspace:

      - If the \`scripts\` field from your local package.json contains a matching script name, its definition will get executed.

      - Otherwise, if one of the local workspace's dependencies exposes a binary with a matching name, this binary will get executed.

      - Otherwise, if the specified name contains a colon character and if one of the workspaces in the project contains exactly one script with a matching name, then this script will get executed.

      Whatever happens, the cwd of the spawned process will be the workspace that declares the script (which makes it possible to call commands cross-workspaces using the third syntax).
    `,
    examples: [[

clipanion

Type-safe CLI library / framework with no runtime dependencies

MIT
Latest version published 4 months ago

Package Health Score

82 / 100
Full package analysis