diff --git a/command/_errors.ts b/command/_errors.ts index f1d486a3..6a20a93f 100644 --- a/command/_errors.ts +++ b/command/_errors.ts @@ -170,15 +170,6 @@ export class DefaultCommandNotFoundError extends CommandError { } } -export class CommandExecutableNotFoundError extends CommandError { - constructor(name: string) { - super( - `Command executable not found: ${name}`, - ); - Object.setPrototypeOf(this, CommandExecutableNotFoundError.prototype); - } -} - export class UnknownCompletionCommandError extends CommandError { constructor(name: string, commands: Array) { super( diff --git a/command/command.ts b/command/command.ts index 01a667e0..96bd3a4a 100644 --- a/command/command.ts +++ b/command/command.ts @@ -13,7 +13,6 @@ import { } from "./_utils.ts"; import { bold, brightBlue, red } from "./deps.ts"; import { - CommandExecutableNotFoundError, CommandNotFoundError, DefaultCommandNotFoundError, DuplicateCommandAliasError, @@ -152,7 +151,6 @@ export class Command< private completions = new Map(); private cmd: Command = this; private argsDefinition?: string; - private isExecutable = false; private throwOnError = false; private _allowEmpty = false; private _stopEarly = false; @@ -793,12 +791,6 @@ export class Command< return this; } - /** Make command executable. */ - public executable(): this { - this.cmd.isExecutable = true; - return this; - } - /** * Set command arguments. * @@ -1718,10 +1710,7 @@ export class Command< this.registerDefaults(); this.rawArgs = ctx.unknown.slice(); - if (this.isExecutable) { - await this.executeExecutable(ctx.unknown); - return { options: {}, args: [], cmd: this, literal: [] }; - } else if (this._useRawArgs) { + if (this._useRawArgs) { await this.parseEnvVars(ctx, this.envVars); return await this.execute(ctx.env, ctx.unknown); } @@ -1966,32 +1955,6 @@ export class Command< await this.globalActionHandler?.(options, ...args); } - /** - * Execute external sub-command. - * @param args Raw command line arguments. - */ - protected async executeExecutable(args: string[]) { - const command = this.getPath().replace(/\s+/g, "-"); - - await Deno.permissions.request({ name: "run", command }); - - try { - const cmd: Deno.Command = new Deno.Command(command, { - args, - }); - const output: Deno.CommandOutput = await cmd.output(); - - if (!output.success) { - Deno.exit(output.code); - } - } catch (error) { - if (error instanceof Deno.errors.NotFound) { - throw new CommandExecutableNotFoundError(command); - } - throw error; - } - } - /** Parse raw command line arguments. */ protected parseOptions( ctx: ParseContext, diff --git a/examples/command/git_style_executables.ts b/examples/command/git_style_executables.ts deleted file mode 100755 index 9b015429..00000000 --- a/examples/command/git_style_executables.ts +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env -S deno run - -import { Command } from "../../command/command.ts"; - -await new Command() - .command("install [name]", "install one or more packages").executable() - .command("search [query]", "search with optional query").executable() - .command("update", "update installed packages").executable() - .command("list", "list packages installed").executable() - .parse(Deno.args); diff --git a/examples/command/sub_commands.ts b/examples/command/sub_commands.ts index 677acdc5..6f054154 100755 --- a/examples/command/sub_commands.ts +++ b/examples/command/sub_commands.ts @@ -25,10 +25,3 @@ await new Command() }), ) .parse(Deno.args); - -// Command implemented using separate executable file (description is passed as second parameter to `.command()`) -await new Command() - .command("start ", "Start named service.").executable() - .command("stop [service]", "Stop named service, or all if no name supplied.") - .executable() - .parse(Deno.args);