How to use the clipanion.Command.String 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-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<CommandContext> {
  @Command.String()
  workspaceName!: string;

  @Command.String()
  commandName!: string;

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

  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`,
github yarnpkg / berry / packages / plugin-pack / sources / commands / pack.ts View on Github external
import * as packUtils                                                                                  from '../packUtils';

// eslint-disable-next-line arca/no-default-export
export default class PackCommand extends BaseCommand {
  @Command.Boolean(`--install-if-needed`)
  installIfNeeded: boolean = false;

  @Command.Boolean(`-n,--dry-run`)
  dryRun: boolean = false;

  @Command.Boolean(`--json`)
  json: boolean = false;

  @Command.String(`--filename`, {hidden: false})
  @Command.String(`-o,--out`)
  out?: string;

  static usage = Command.Usage({
    description: `generate a tarball from the active workspace`,
    details: `
      This command will turn the active workspace into a compressed archive suitable for publishing. The archive will by default be stored at the root of the workspace (\`package.tgz\`).

      If the \`--install-if-needed\` flag is set Yarn will run a preliminary \`yarn install\` if the package contains build scripts.

      If the \`-n,--dry-run\` flag is set the command will just print the file paths without actually generating the package archive.

      If the \`--json\` flag is set the output will follow a JSON-stream output also known as NDJSON (https://github.com/ndjson/ndjson-spec).

      If the \`-o,---out\` is set the archive will be created at the specified path. The \`%s\` and \`%v\` variables can be used within the path and will be respectively replaced by the package name and version.
    `,
    examples: [[
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<CommandContext> {
  @Command.String()
  leadingArgument!: string;

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

  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-constraints / sources / commands / constraints / query.ts View on Github external
import {BaseCommand}            from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {StreamReport}           from '@yarnpkg/core';
import {Command}                from 'clipanion';

import {Constraints}            from '../../Constraints';

// eslint-disable-next-line arca/no-default-export
export default class ConstraintsQueryCommand extends BaseCommand {
  @Command.Boolean(`--json`)
  json: boolean = false;

  @Command.String()
  query!: string;

  static usage = Command.Usage({
    category: `Constraints-related commands`,
    description: `query the constraints fact database`,
    details: `
      This command will output all matches to the given prolog query.

      If the \`--json\` flag is set the output will follow a JSON-stream output also known as NDJSON (https://github.com/ndjson/ndjson-spec).
    `,
    examples: [[
      `List all dependencies throughout the workspace`,
      `yarn constraints query 'workspace_has_dependency(_, DependencyName, _, _).'`,
    ]],
  });
github yarnpkg / berry / packages / yarnpkg-builder / sources / commands / build / bundle.ts View on Github external
import path          from 'path';
import TerserPlugin  from 'terser-webpack-plugin';
import webpack       from 'webpack';

import {dynamicLibs} from '../../data/dynamicLibs';
import {findPlugins} from '../../tools/findPlugins';
import {makeConfig}  from '../../tools/makeConfig';

const pkgJsonVersion = (basedir: string) => {
  const pkgJson = require(`${basedir}/package.json`);
  return JSON.stringify(pkgJson["version"]);
};

// eslint-disable-next-line arca/no-default-export
export default class BuildBundleCommand extends Command {
  @Command.String(`--profile`)
  profile: string = `standard`;

  @Command.Array(`--plugin`)
  plugins: Array<string> = [];

  @Command.Boolean(`--no-minify`)
  noMinify: boolean = false;

  static usage = Command.Usage({
    description: `build the local bundle`,
  });

  @Command.Path(`build`, `bundle`)
  async execute() {
    const basedir = process.cwd();
    const plugins = findPlugins({basedir, profile: this.profile, plugins: this.plugins});
github yarnpkg / berry / packages / plugin-dlx / sources / commands / dlx.ts View on Github external
import {BaseCommand, WorkspaceRequiredError}                   from '@yarnpkg/cli';
import {Configuration, Project}                                from '@yarnpkg/core';
import {scriptUtils, structUtils}                              from '@yarnpkg/core';
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<string> = [];

  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.
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / login.ts View on Github external
import {BaseCommand, openWorkspace}   from '@yarnpkg/cli';
import {Configuration, MessageName}   from '@yarnpkg/core';
import {StreamReport}                 from '@yarnpkg/core';
import {npmConfigUtils, npmHttpUtils} from '@yarnpkg/plugin-npm';
import {Command}                      from 'clipanion';
import inquirer                       from 'inquirer';

// eslint-disable-next-line arca/no-default-export
export default class NpmLoginCommand extends BaseCommand {
  @Command.String(`-s,--scope`)
  scope?: string;

  @Command.Boolean(`--publish`)
  publish: boolean = false;

  static usage = Command.Usage({
    category: `Npm-related commands`,
    description: `store new login info to access the npm registry`,
    details: `
      This command will ask you for your username, password, and 2FA One-Time-Password (when it applies). It will then modify your local configuration (in your home folder, never in the project itself) to reference the new tokens thus generated.

      Adding the \`-s,--scope\` flag will cause the authentication to be done against whatever registry is configured for the associated scope (see also \`npmScopes\`).

      Adding the \`--publish\` flag will cause the authentication to be done against the registry used when publishing the package (see also \`publishConfig.registry\` and \`npmPublishRegistry\`).
    `,
    examples: [[
github yarnpkg / berry / packages / plugin-init / sources / commands / init.ts View on Github external
import {Configuration, Manifest}             from '@yarnpkg/core';
import {execUtils, scriptUtils, structUtils} from '@yarnpkg/core';
import {xfs, ppath, Filename}                from '@yarnpkg/fslib';
import {updateAndSave}                       from '@yarnpkg/json-proxy';
import {Command, UsageError}                 from 'clipanion';
import {inspect}                             from 'util';

// eslint-disable-next-line arca/no-default-export
export default class InitCommand extends BaseCommand {
  @Command.Boolean(`-y,--yes`, {hidden: true})
  yes: boolean = false;

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

  @Command.String(`-i,--install`)
  install?: string;

  static usage = Command.Usage({
    description: `create a new package`,
    details: `
      This command will setup a new package in your local directory.

      If the \`-p,--private\` option is set, the package will be private by default.

      If the \`-i,--install\` option is given a value, Yarn will first download it using \`yarn set version\` and only then forward the init call to the newly downloaded bundle.

      The following settings can be used in order to affect what the generated package.json will look like:

      - \`initLicense\`
      - \`initScope\`
      - \`initVersion\`
github yarnpkg / berry / packages / plugin-essentials / sources / commands / plugin / import.ts View on Github external
import {BaseCommand}                                                    from '@yarnpkg/cli';
import {Configuration, MessageName, Project, ReportError, StreamReport} from '@yarnpkg/core';
import {httpUtils, structUtils}                                         from '@yarnpkg/core';
import {xfs, NodeFS, PortablePath, ppath}                               from '@yarnpkg/fslib';
import {Command}                                                        from 'clipanion';
import {runInNewContext}                                                from 'vm';

import {getAvailablePlugins}                                            from './list';

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

  static usage = Command.Usage({
    category: `Plugin-related commands`,
    description: `download a plugin`,
    details: `
      This command downloads the specified plugin from its remote location and updates the configuration to reference it in further CLI invocations.

      Three types of plugin references are accepted:

      - If the plugin is stored within the Yarn repository, it can be referenced by name.
      - Third-party plugins can be referenced directly through their public urls.
      - Local plugins can be referenced by their path on the disk.

      Plugins cannot be downloaded from the npm registry, and aren't allowed to have dependencies (they need to be bundled into a single file, possibly thanks to the \`@yarnpkg/builder\` package).
    `,
github yarnpkg / berry / packages / plugin-essentials / sources / commands / install.ts View on Github external
@Command.Boolean(`--check-cache`)
  checkCache: boolean = false;

  @Command.Boolean(`--frozen-lockfile`, {hidden: true})
  frozenLockfile?: boolean;

  @Command.Boolean(`--prefer-offline`, {hidden: true})
  preferOffline?: boolean;

  @Command.Boolean(`--ignore-engines`, {hidden: true})
  ignoreEngines?: boolean;

  @Command.Boolean(`--inline-builds`)
  inlineBuilds?: boolean;

  @Command.String(`--cache-folder`)
  cacheFolder?: string;

  static usage = Command.Usage({
    description: `install the project dependencies`,
    details: `
      This command setup your project if needed. The installation is splitted in four different steps that each have their own characteristics:

      - **Resolution:** First the package manager will resolve your dependencies. The exact way a dependency version is privileged over another isn't standardized outside of the regular semver guarantees. If a package doesn't resolve to what you would expect, check that all dependencies are correctly declared (also check our website for more information: ).

      - **Fetch:** Then we download all the dependencies if needed, and make sure that they're all stored within our cache (check the value of \`cache-folder\` in \`yarn config\` to see where are stored the cache files).

      - **Link:** Then we send the dependency tree information to internal plugins tasked from writing them on the disk in some form (for example by generating the .pnp.js file you might know).

      - **Build:** Once the dependency tree has been written on the disk, the package manager will now be free to run the build scripts for all packages that might need it, in a topological order compatible with the way they depend on one another.

      Note that running this command is not part of the recommended workflow. Yarn supports zero-installs, which means that as long as you store your cache and your .pnp.js file inside your repository, everything will work without requiring any install right after cloning your repository or switching branches.