Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

cli: refine missing-value tip

jkomyno5b93076711b8
diff --git a/ts/packages/cli/src/bin.ts b/ts/packages/cli/src/bin.ts
index b9a501770..f246d7042 100644
--- a/ts/packages/cli/src/bin.ts
+++ b/ts/packages/cli/src/bin.ts
@@ -1,11 +1,11 @@
import process from 'node:process';
-import { Cause, Console, Effect, Exit, Layer, Logger } from 'effect';
+import { Cause, Console, Effect, Exit, HashMap, Layer, Logger, Option } from 'effect';
import { captureErrors, prettyPrintFromCapturedErrors } from 'effect-errors/index';
-import { CliConfig, HelpDoc, ValidationError } from '@effect/cli';
+import { CliConfig, Command, HelpDoc, Usage, ValidationError } from '@effect/cli';
import { FetchHttpClient } from '@effect/platform';
import { BunContext, BunRuntime, BunFileSystem } from '@effect/platform-bun';
import type { Teardown } from '@effect/platform/Runtime';
-import { runWithConfig } from 'src/commands';
+import { rootCommand, runWithConfig } from 'src/commands';
import * as constants from 'src/constants';
import { ComposioCliConfig } from 'src/cli-config';
import { BaseConfigProviderLive, ConfigLive, extendConfigProvider } from 'src/services/config';
@@ -93,6 +93,48 @@ const runWithArgs = Effect.flatMap(runWithConfig, run => run(process.argv)) sati
unknown
>;
+const collectValueOptionNamesFromUsage = (usage: Usage.Usage, acc: Set<string>) => {
+ switch (usage._tag) {
+ case 'Named': {
+ if (Option.isSome(usage.acceptedValues)) {
+ for (const name of usage.names) {
+ if (name.startsWith('-')) {
+ acc.add(name);
+ }
+ }
+ }
+ return;
+ }
+ case 'Optional':
+ case 'Repeated': {
+ collectValueOptionNamesFromUsage(usage.usage, acc);
+ return;
+ }
+ case 'Alternation':
+ case 'Concat': {
+ collectValueOptionNamesFromUsage(usage.left, acc);
+ collectValueOptionNamesFromUsage(usage.right, acc);
+ return;
+ }
+ case 'Mixed':
+ case 'Empty': {
+ return;
+ }
+ }
+};
+
+const valueOptionNames = (() => {
+ const names = new Set<string>();
+ const visit = (command: Command.Command<unknown>) => {
+ collectValueOptionNamesFromUsage(Command.getUsage(command), names);
+ for (const [, subcommand] of HashMap.toEntries(Command.getSubcommands(command))) {
+ visit(subcommand);
+ }
+ };
+ visit(rootCommand);
+ return names;
+})();
+
/**
* CLI entrypoint, which:
* - runs the Effect runtime and sets up its runtime environment
@@ -108,7 +150,7 @@ runWithArgs.pipe(
Effect.catchIf(ValidationError.isValidationError, error => {
const text = HelpDoc.toAnsiText(error.error).trim();
const flagMatch = text.match(/Received unknown argument: '(-{1,2}[\w-]+)'/);
- if (flagMatch) {
+ if (flagMatch && valueOptionNames.has(flagMatch[1])) {
return Console.error(`Tip: ${flagMatch[1]} requires a value, e.g. ${flagMatch[1]} "value"`);
}
return Effect.void;
diff --git a/ts/packages/cli/src/commands/index.ts b/ts/packages/cli/src/commands/index.ts
index 1f198384d..7d23633b5 100644
--- a/ts/packages/cli/src/commands/index.ts
+++ b/ts/packages/cli/src/commands/index.ts
@@ -27,6 +27,8 @@ const $cmd = $defaultCmd.pipe(
])
);
+export const rootCommand = $cmd;
+
export const runWithConfig = Effect.gen(function* () {
const version = yield* getVersion;