How to use the clipanion.Command.Path 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-essentials / sources / commands / runIndex.ts View on Github external
import {BaseCommand, WorkspaceRequiredError}  from '@yarnpkg/cli';
import {Configuration, Project, StreamReport} from '@yarnpkg/core';
import {miscUtils}                            from '@yarnpkg/core';
import {Command}                              from 'clipanion';
import {inspect}                              from 'util';

// eslint-disable-next-line arca/no-default-export
export default class RunCommand extends BaseCommand {
  @Command.Path(`run`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async report => {
      const scripts = workspace!.manifest.scripts;
      const keys = miscUtils.sortMap(scripts.keys(), key => key);
      const inspectConfig = {
        breakLength: Infinity,
        colors: configuration.get(`enableColors`),
github yarnpkg / berry / packages / yarnpkg-builder / sources / commands / build / bundle.ts View on Github external
// 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 = [];

  @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});
    const modules = Array.from(dynamicLibs).concat(plugins);
    const output = `${basedir}/bundles/yarn.js`;

    const compiler = webpack(makeConfig({
      context: basedir,
      entry: `./sources/cli.ts`,

      bail: true,

      ...!this.noMinify && {
        mode: `production`,
      },
github yarnpkg / berry / packages / yarnpkg-builder / sources / commands / new / plugin.ts View on Github external
import {Filename, npath, ppath, xfs} from '@yarnpkg/fslib';
import chalk                         from 'chalk';
import {Command, UsageError}         from 'clipanion';
import path                          from 'path';

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

  static usage = Command.Usage({
    description: `generate the template for a new plugin`,
  });

  @Command.Path(`new`, `plugin`)
  async execute() {
    const target = npath.toPortablePath(path.resolve(this.target));
    if (await xfs.existsPromise(target)) {
      const listing = await xfs.readdirPromise(target);
      if (listing.length !== 0) {
        throw new UsageError(`The target directory (${this.target}) isn't empty; aborting the scaffolding.`);
      }
    }

    await xfs.mkdirpPromise(target);
    await xfs.mkdirpPromise(ppath.join(target, `sources` as Filename));

    await xfs.writeFilePromise(ppath.join(target, `sources/index.ts` as Filename), [
      `import {CommandContext, Plugin} from '@yarnpkg/core';\n`,
      `import {Command} from 'clipanion';\n`,
      `\n`,
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.ts View on Github external
details: `
      **Warning:** This command currently requires Git.

      This command will check that all the packages covered by the files listed in argument have been properly bumped or declined to bump.

      In the case of a bump, the check will also cover transitive packages - meaning that should \`Foo\` be bumped, a package \`Bar\` depending on \`Foo\` will require a decision as to whether \`Bar\` will need to be bumped. This check doesn't cross packages that have declined to bump.

      In case no arguments are passed to the function, the list of modified files will be generated by comparing the HEAD against \`master\`.
    `,
    examples: [[
      `Check whether the modified packages need a bump`,
      `yarn version check`,
    ]],
  });

  @Command.Path(`version`, `check`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async report => {
      const root = await fetchRoot(this.context.cwd);
      const base = await fetchBase(root);

      const files = await fetchChangedFiles(root, {base: base.hash});
      const workspaces = new Set(files.map(file => project.getWorkspaceByFilePath(file)));
github yarnpkg / berry / packages / plugin-essentials / sources / commands / set / version / sources.ts View on Github external
@Command.Boolean(`-f,--force`)
  force: boolean = false;

  static usage = Command.Usage({
    description: `build Yarn from master`,
    details: `
      This command will clone the Yarn repository into a temporary folder, then build it. The resulting bundle will then be copied into the local project.
    `,
    examples: [[
      `Build Yarn from master`,
      `$0 set version from sources`,
    ]],
  });

  @Command.Path(`set`, `version`, `from`, `sources`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const target = typeof this.installPath !== `undefined`
      ? ppath.resolve(this.context.cwd, toPortablePath(this.installPath))
      : ppath.resolve(toPortablePath(tmpdir()), `yarnpkg-sources` as Filename);

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async (report: StreamReport) => {
      const runWorkflow = async (workflow: Array>) => {
github yarnpkg / berry / packages / plugin-workspace-tools / sources / commands / workspace.ts View on Github external
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`,
    ]],
  });

  @Command.Path(`workspace`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace: cwdWorkspace} = await Project.find(configuration, this.context.cwd);

    if (!cwdWorkspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const candidates = project.workspaces;
    const candidatesByName = new Map(
      candidates.map(
        (workspace): [string, Workspace] => {
          const ident = structUtils.convertToIdent(workspace.locator);
          return [structUtils.stringifyIdent(ident), workspace];
        }
      )
    );
github yarnpkg / berry / packages / plugin-init / sources / commands / init.ts View on Github external
- \`initScope\`
      - \`initVersion\`
    `,
    examples: [[
      `Create a new package in the local directory`,
      `yarn init`,
    ], [
      `Create a new private package in the local directory`,
      `yarn init -p`,
    ], [
      `Create a new package and store the Yarn release inside`,
      `yarn init -i berry`,
    ]],
  });

  @Command.Path(`init`)
  async execute() {
    if (xfs.existsSync(ppath.join(this.context.cwd, Manifest.fileName)))
      throw new UsageError(`A package.json already exists in the specified directory`);

    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

    if (typeof this.install !== `undefined`) {
      return await this.executeProxy(configuration);
    } else {
      return await this.executeRegular(configuration);
    }
  }

  async executeProxy(configuration: Configuration) {
    if (configuration.get(`yarnPath`) !== null)
      throw new UsageError(`Cannot use the --install flag when the current directory already uses yarnPath (from ${configuration.sources.get(`yarnPath`)})`);
github yarnpkg / berry / packages / plugin-essentials / sources / commands / why.ts View on Github external
static usage = Command.Usage({
    description: `display the reason why a package is needed`,
    details: `
      This command prints the exact reasons why a package appears in the dependency tree.

      If \`-R,--recursive\` is set, the listing will go in depth and will list, for each workspaces, what are all the paths that lead to the dependency. Note that the display is somewhat optimized in that it will not print the package listing twice for a single package, so if you see a leaf named "Foo" when looking for "Bar", it means that "Foo" already got printed higher in the tree.

      If \`--peers\` is set, the command will also print the peer dependencies that match the specified name.
    `,
    examples: [[
      `Explain why lodash is used in your project`,
      `$0 why lodash`,
    ]],
  });

  @Command.Path(`why`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const identHash = structUtils.parseIdent(this.package).identHash;

    const whyTree = this.recursive
      ? whyRecursive(project, identHash, {configuration, peers: this.peers})
      : whySimple(project, identHash, {configuration, peers: this.peers});

    printTree(this.context.stdout, whyTree);
  }
}
github yarnpkg / berry / packages / plugin-essentials / sources / commands / config.ts View on Github external
When used together with the \`-v,--verbose\` option, the output will contain the settings description on top of the regular key/value information.

      When used together with the \`--why\` flag, the output will also contain the reason why a settings is set a particular way.

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

      Note that the paths settings will be normalized - especially on Windows. It means that paths such as \`C:\\project\` will be transparently shown as \`/mnt/c/project\`.
    `,
    examples: [[
      `Print the active configuration settings`,
      `yarn config`,
    ]],
  });

  @Command.Path(`config`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins, {
      strict: false,
    });

    const getValue = (key: string) => {
      const isSecret = configuration.settings.get(key)!.type === SettingsType.SECRET;
      const rawValue = configuration.values.get(key)!;

      if (isSecret && typeof rawValue === `string`) {
        return `********`;
      } else {
        return rawValue;
      }
    };
github yarnpkg / berry / packages / plugin-pack / sources / commands / pack.ts View on Github external
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: [[
      `Create an archive from the active workspace`,
      `yarn pack`,
    ], [
      `List the files that would be made part of the workspace's archive`,
      `yarn pack --dry-run`,
    ], [
      `Name and output the archive in a dedicated folder`,
      `yarn pack --out /artifacts/%s-%v.tgz`,
    ]],
  });

  @Command.Path(`pack`)
  async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    if (await packUtils.hasPackScripts(workspace)) {
      if (this.installIfNeeded) {
        await project.install({
          cache: await Cache.find(configuration),
          report: new ThrowReport(),
        });
      } else {
        await project.resolveEverything({
          lockfileOnly: true,

clipanion

Type-safe CLI library / framework with no runtime dependencies

MIT
Latest version published 13 days ago

Package Health Score

85 / 100
Full package analysis