@claude-flow/cli 3.0.0-alpha.2 → 3.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -6
- package/bin/cli.js +0 -0
- package/dist/src/commands/agent.d.ts.map +1 -1
- package/dist/src/commands/agent.js +43 -27
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/analyze.d.ts +19 -0
- package/dist/src/commands/analyze.d.ts.map +1 -0
- package/dist/src/commands/analyze.js +1823 -0
- package/dist/src/commands/analyze.js.map +1 -0
- package/dist/src/commands/claims.d.ts +10 -0
- package/dist/src/commands/claims.d.ts.map +1 -0
- package/dist/src/commands/claims.js +288 -0
- package/dist/src/commands/claims.js.map +1 -0
- package/dist/src/commands/completions.d.ts +10 -0
- package/dist/src/commands/completions.d.ts.map +1 -0
- package/dist/src/commands/completions.js +539 -0
- package/dist/src/commands/completions.js.map +1 -0
- package/dist/src/commands/config.js +2 -2
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/daemon.d.ts +8 -0
- package/dist/src/commands/daemon.d.ts.map +1 -0
- package/dist/src/commands/daemon.js +545 -0
- package/dist/src/commands/daemon.js.map +1 -0
- package/dist/src/commands/deployment.d.ts +10 -0
- package/dist/src/commands/deployment.d.ts.map +1 -0
- package/dist/src/commands/deployment.js +289 -0
- package/dist/src/commands/deployment.js.map +1 -0
- package/dist/src/commands/doctor.d.ts +10 -0
- package/dist/src/commands/doctor.d.ts.map +1 -0
- package/dist/src/commands/doctor.js +429 -0
- package/dist/src/commands/doctor.js.map +1 -0
- package/dist/src/commands/embeddings.d.ts +18 -0
- package/dist/src/commands/embeddings.d.ts.map +1 -0
- package/dist/src/commands/embeddings.js +616 -0
- package/dist/src/commands/embeddings.js.map +1 -0
- package/dist/src/commands/hive-mind.d.ts.map +1 -1
- package/dist/src/commands/hive-mind.js +252 -35
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/commands/hooks.d.ts.map +1 -1
- package/dist/src/commands/hooks.js +326 -2
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +13 -0
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +52 -1
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/mcp.js +4 -4
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/memory.d.ts.map +1 -1
- package/dist/src/commands/memory.js +236 -170
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.js +1 -1
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/neural.d.ts +10 -0
- package/dist/src/commands/neural.d.ts.map +1 -0
- package/dist/src/commands/neural.js +224 -0
- package/dist/src/commands/neural.js.map +1 -0
- package/dist/src/commands/performance.d.ts +10 -0
- package/dist/src/commands/performance.d.ts.map +1 -0
- package/dist/src/commands/performance.js +262 -0
- package/dist/src/commands/performance.js.map +1 -0
- package/dist/src/commands/plugins.d.ts +10 -0
- package/dist/src/commands/plugins.d.ts.map +1 -0
- package/dist/src/commands/plugins.js +280 -0
- package/dist/src/commands/plugins.js.map +1 -0
- package/dist/src/commands/process.d.ts.map +1 -1
- package/dist/src/commands/process.js +95 -20
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/providers.d.ts +10 -0
- package/dist/src/commands/providers.d.ts.map +1 -0
- package/dist/src/commands/providers.js +232 -0
- package/dist/src/commands/providers.js.map +1 -0
- package/dist/src/commands/route.d.ts +16 -0
- package/dist/src/commands/route.d.ts.map +1 -0
- package/dist/src/commands/route.js +603 -0
- package/dist/src/commands/route.js.map +1 -0
- package/dist/src/commands/security.d.ts +10 -0
- package/dist/src/commands/security.d.ts.map +1 -0
- package/dist/src/commands/security.js +261 -0
- package/dist/src/commands/security.js.map +1 -0
- package/dist/src/commands/start.js +2 -2
- package/dist/src/commands/start.js.map +1 -1
- package/dist/src/commands/status.d.ts.map +1 -1
- package/dist/src/commands/status.js +26 -2
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.js +6 -6
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +63 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/claudemd-generator.d.ts.map +1 -1
- package/dist/src/init/claudemd-generator.js +218 -362
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts.map +1 -1
- package/dist/src/init/executor.js +5 -0
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/settings-generator.d.ts.map +1 -1
- package/dist/src/init/settings-generator.js +22 -12
- package/dist/src/init/settings-generator.js.map +1 -1
- package/dist/src/mcp-client.d.ts.map +1 -1
- package/dist/src/mcp-client.js +17 -1
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +5 -0
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.d.ts +1 -1
- package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +350 -14
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/analyze-tools.d.ts +38 -0
- package/dist/src/mcp-tools/analyze-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/analyze-tools.js +317 -0
- package/dist/src/mcp-tools/analyze-tools.js.map +1 -0
- package/dist/src/mcp-tools/config-tools.d.ts +1 -1
- package/dist/src/mcp-tools/config-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/config-tools.js +262 -15
- package/dist/src/mcp-tools/config-tools.js.map +1 -1
- package/dist/src/mcp-tools/hive-mind-tools.d.ts +8 -0
- package/dist/src/mcp-tools/hive-mind-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/hive-mind-tools.js +447 -0
- package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +80 -15
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/index.d.ts +6 -0
- package/dist/src/mcp-tools/index.d.ts.map +1 -1
- package/dist/src/mcp-tools/index.js +6 -0
- package/dist/src/mcp-tools/index.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.d.ts +1 -1
- package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +157 -9
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/mcp-tools/session-tools.d.ts +8 -0
- package/dist/src/mcp-tools/session-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/session-tools.js +315 -0
- package/dist/src/mcp-tools/session-tools.js.map +1 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +37 -2
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/mcp-tools/task-tools.d.ts +8 -0
- package/dist/src/mcp-tools/task-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/task-tools.js +302 -0
- package/dist/src/mcp-tools/task-tools.js.map +1 -0
- package/dist/src/mcp-tools/workflow-tools.d.ts +8 -0
- package/dist/src/mcp-tools/workflow-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/workflow-tools.js +481 -0
- package/dist/src/mcp-tools/workflow-tools.js.map +1 -0
- package/dist/src/output.d.ts +16 -0
- package/dist/src/output.d.ts.map +1 -1
- package/dist/src/output.js +42 -0
- package/dist/src/output.js.map +1 -1
- package/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/dist/src/ruvector/ast-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/ast-analyzer.js +277 -0
- package/dist/src/ruvector/ast-analyzer.js.map +1 -0
- package/dist/src/ruvector/coverage-router.d.ts +145 -0
- package/dist/src/ruvector/coverage-router.d.ts.map +1 -0
- package/dist/src/ruvector/coverage-router.js +451 -0
- package/dist/src/ruvector/coverage-router.js.map +1 -0
- package/dist/src/ruvector/coverage-tools.d.ts +33 -0
- package/dist/src/ruvector/coverage-tools.d.ts.map +1 -0
- package/dist/src/ruvector/coverage-tools.js +157 -0
- package/dist/src/ruvector/coverage-tools.js.map +1 -0
- package/dist/src/ruvector/diff-classifier.d.ts +154 -0
- package/dist/src/ruvector/diff-classifier.d.ts.map +1 -0
- package/dist/src/ruvector/diff-classifier.js +508 -0
- package/dist/src/ruvector/diff-classifier.js.map +1 -0
- package/dist/src/ruvector/graph-analyzer.d.ts +174 -0
- package/dist/src/ruvector/graph-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/graph-analyzer.js +878 -0
- package/dist/src/ruvector/graph-analyzer.js.map +1 -0
- package/dist/src/ruvector/index.d.ts +27 -0
- package/dist/src/ruvector/index.d.ts.map +1 -0
- package/dist/src/ruvector/index.js +47 -0
- package/dist/src/ruvector/index.js.map +1 -0
- package/dist/src/ruvector/q-learning-router.d.ts +211 -0
- package/dist/src/ruvector/q-learning-router.d.ts.map +1 -0
- package/dist/src/ruvector/q-learning-router.js +681 -0
- package/dist/src/ruvector/q-learning-router.js.map +1 -0
- package/dist/src/ruvector/vector-db.d.ts +69 -0
- package/dist/src/ruvector/vector-db.d.ts.map +1 -0
- package/dist/src/ruvector/vector-db.js +243 -0
- package/dist/src/ruvector/vector-db.js.map +1 -0
- package/dist/src/services/index.d.ts +7 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +6 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/worker-daemon.d.ts +153 -0
- package/dist/src/services/worker-daemon.d.ts.map +1 -0
- package/dist/src/services/worker-daemon.js +567 -0
- package/dist/src/services/worker-daemon.js.map +1 -0
- package/dist/src/suggest.d.ts +53 -0
- package/dist/src/suggest.d.ts.map +1 -0
- package/dist/src/suggest.js +200 -0
- package/dist/src/suggest.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -6
- package/.agentic-flow/intelligence.json +0 -16
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/performance.json +0 -87
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/__tests__/README.md +0 -140
- package/__tests__/TEST_SUMMARY.md +0 -144
- package/__tests__/cli.test.ts +0 -558
- package/__tests__/commands.test.ts +0 -726
- package/__tests__/config-adapter.test.ts +0 -362
- package/__tests__/config-loading.test.ts +0 -106
- package/__tests__/coverage/.tmp/coverage-0.json +0 -1
- package/__tests__/coverage/.tmp/coverage-1.json +0 -1
- package/__tests__/coverage/.tmp/coverage-2.json +0 -1
- package/__tests__/coverage/.tmp/coverage-3.json +0 -1
- package/__tests__/coverage/.tmp/coverage-4.json +0 -1
- package/__tests__/coverage/.tmp/coverage-5.json +0 -1
- package/__tests__/mcp-client.test.ts +0 -480
- package/__tests__/p1-commands.test.ts +0 -1064
- package/docs/CONFIG_LOADING.md +0 -236
- package/docs/IMPLEMENTATION_COMPLETE.md +0 -421
- package/docs/MCP_CLIENT_GUIDE.md +0 -620
- package/docs/REFACTORING_SUMMARY.md +0 -247
- package/src/commands/agent.ts +0 -941
- package/src/commands/config.ts +0 -452
- package/src/commands/hive-mind.ts +0 -762
- package/src/commands/hooks.ts +0 -2603
- package/src/commands/index.ts +0 -115
- package/src/commands/init.ts +0 -597
- package/src/commands/mcp.ts +0 -753
- package/src/commands/memory.ts +0 -1063
- package/src/commands/migrate.ts +0 -447
- package/src/commands/process.ts +0 -617
- package/src/commands/session.ts +0 -891
- package/src/commands/start.ts +0 -457
- package/src/commands/status.ts +0 -705
- package/src/commands/swarm.ts +0 -648
- package/src/commands/task.ts +0 -792
- package/src/commands/workflow.ts +0 -742
- package/src/config-adapter.ts +0 -210
- package/src/index.ts +0 -383
- package/src/infrastructure/in-memory-repositories.ts +0 -310
- package/src/init/claudemd-generator.ts +0 -631
- package/src/init/executor.ts +0 -756
- package/src/init/helpers-generator.ts +0 -628
- package/src/init/index.ts +0 -60
- package/src/init/mcp-generator.ts +0 -83
- package/src/init/settings-generator.ts +0 -274
- package/src/init/statusline-generator.ts +0 -211
- package/src/init/types.ts +0 -447
- package/src/mcp-client.ts +0 -227
- package/src/mcp-server.ts +0 -571
- package/src/mcp-tools/agent-tools.ts +0 -92
- package/src/mcp-tools/config-tools.ts +0 -88
- package/src/mcp-tools/hooks-tools.ts +0 -1819
- package/src/mcp-tools/index.ts +0 -12
- package/src/mcp-tools/memory-tools.ts +0 -89
- package/src/mcp-tools/swarm-tools.ts +0 -69
- package/src/mcp-tools/types.ts +0 -33
- package/src/output.ts +0 -593
- package/src/parser.ts +0 -417
- package/src/prompt.ts +0 -619
- package/src/types.ts +0 -287
- package/tmp.json +0 -0
- package/tsconfig.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -13
package/__tests__/cli.test.ts
DELETED
|
@@ -1,558 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 CLI Main Tests
|
|
3
|
-
* Comprehensive tests for CLI parsing, help output, version, and error handling
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
7
|
-
import { CLI, VERSION } from '../src/index.js';
|
|
8
|
-
import type { Command } from '../src/types.js';
|
|
9
|
-
|
|
10
|
-
describe('CLI', () => {
|
|
11
|
-
let cli: CLI;
|
|
12
|
-
let consoleOutput: string[];
|
|
13
|
-
let consoleErrorOutput: string[];
|
|
14
|
-
let processExitMock: ReturnType<typeof vi.spyOn>;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
// Capture console output
|
|
18
|
-
consoleOutput = [];
|
|
19
|
-
consoleErrorOutput = [];
|
|
20
|
-
|
|
21
|
-
vi.spyOn(process.stdout, 'write').mockImplementation((str: string | Uint8Array) => {
|
|
22
|
-
consoleOutput.push(String(str));
|
|
23
|
-
return true;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
vi.spyOn(process.stderr, 'write').mockImplementation((str: string | Uint8Array) => {
|
|
27
|
-
consoleErrorOutput.push(String(str));
|
|
28
|
-
return true;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Mock process.exit to prevent actual exits
|
|
32
|
-
processExitMock = vi.spyOn(process, 'exit').mockImplementation((code?: string | number | null | undefined) => {
|
|
33
|
-
throw new Error(`process.exit: ${code}`);
|
|
34
|
-
}) as unknown as ReturnType<typeof vi.spyOn>;
|
|
35
|
-
|
|
36
|
-
// Create CLI instance (non-interactive for testing)
|
|
37
|
-
cli = new CLI({ interactive: false });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
afterEach(() => {
|
|
41
|
-
vi.restoreAllMocks();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('Version Command', () => {
|
|
45
|
-
it('should show version with --version flag', async () => {
|
|
46
|
-
await cli.run(['--version']);
|
|
47
|
-
|
|
48
|
-
const output = consoleOutput.join('');
|
|
49
|
-
expect(output).toContain('claude-flow');
|
|
50
|
-
expect(output).toContain(VERSION);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should show version with -V flag', async () => {
|
|
54
|
-
await cli.run(['-V']);
|
|
55
|
-
|
|
56
|
-
const output = consoleOutput.join('');
|
|
57
|
-
expect(output).toContain('claude-flow');
|
|
58
|
-
expect(output).toContain(VERSION);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should show version with correct format', async () => {
|
|
62
|
-
await cli.run(['--version']);
|
|
63
|
-
|
|
64
|
-
const output = consoleOutput.join('');
|
|
65
|
-
expect(output).toMatch(/claude-flow v\d+\.\d+\.\d+/);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('Help Command', () => {
|
|
70
|
-
it('should show help when no command provided', async () => {
|
|
71
|
-
await cli.run([]);
|
|
72
|
-
|
|
73
|
-
const output = consoleOutput.join('');
|
|
74
|
-
expect(output).toContain('USAGE:');
|
|
75
|
-
expect(output).toContain('COMMANDS:');
|
|
76
|
-
expect(output).toContain('GLOBAL OPTIONS:');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should show help with --help flag', async () => {
|
|
80
|
-
await cli.run(['--help']);
|
|
81
|
-
|
|
82
|
-
const output = consoleOutput.join('');
|
|
83
|
-
expect(output).toContain('USAGE:');
|
|
84
|
-
expect(output).toContain('COMMANDS:');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should show help with -h flag', async () => {
|
|
88
|
-
await cli.run(['-h']);
|
|
89
|
-
|
|
90
|
-
const output = consoleOutput.join('');
|
|
91
|
-
expect(output).toContain('USAGE:');
|
|
92
|
-
expect(output).toContain('COMMANDS:');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should show command-specific help', async () => {
|
|
96
|
-
await cli.run(['agent', '--help']);
|
|
97
|
-
|
|
98
|
-
const output = consoleOutput.join('');
|
|
99
|
-
expect(output).toContain('agent');
|
|
100
|
-
expect(output).toContain('Agent management');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should list all available commands', async () => {
|
|
104
|
-
await cli.run(['--help']);
|
|
105
|
-
|
|
106
|
-
const output = consoleOutput.join('');
|
|
107
|
-
expect(output).toContain('agent');
|
|
108
|
-
expect(output).toContain('swarm');
|
|
109
|
-
expect(output).toContain('memory');
|
|
110
|
-
expect(output).toContain('config');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should show V3 features in help', async () => {
|
|
114
|
-
await cli.run(['--help']);
|
|
115
|
-
|
|
116
|
-
const output = consoleOutput.join('');
|
|
117
|
-
expect(output).toContain('V3 FEATURES:');
|
|
118
|
-
expect(output).toContain('15-agent');
|
|
119
|
-
expect(output).toContain('AgentDB');
|
|
120
|
-
expect(output).toContain('Flash Attention');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should show examples in help', async () => {
|
|
124
|
-
await cli.run(['--help']);
|
|
125
|
-
|
|
126
|
-
const output = consoleOutput.join('');
|
|
127
|
-
expect(output).toContain('EXAMPLES:');
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe('Invalid Commands', () => {
|
|
132
|
-
it('should show error for unknown command', async () => {
|
|
133
|
-
// Reset output
|
|
134
|
-
consoleOutput = [];
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
await cli.run(['invalid-command']);
|
|
138
|
-
// Should throw, but might not in current implementation
|
|
139
|
-
} catch (e) {
|
|
140
|
-
// Error may or may not be thrown
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const output = consoleOutput.join('');
|
|
144
|
-
// Check that output contains either error message or help
|
|
145
|
-
const hasError = output.includes('Unknown command') || output.includes('invalid-command');
|
|
146
|
-
const hasHelp = output.includes('USAGE:') || output.includes('COMMANDS:');
|
|
147
|
-
expect(hasError || hasHelp).toBe(true);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('should suggest help for unknown command', async () => {
|
|
151
|
-
consoleOutput = [];
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
await cli.run(['nonexistent']);
|
|
155
|
-
} catch (e) {
|
|
156
|
-
// Error may or may not be thrown
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const output = consoleOutput.join('');
|
|
160
|
-
// Either shows error or help
|
|
161
|
-
const hasMessage = output.includes('nonexistent') || output.includes('help') || output.includes('COMMANDS:');
|
|
162
|
-
expect(hasMessage).toBe(true);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should handle misspelled commands', async () => {
|
|
166
|
-
consoleOutput = [];
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
await cli.run(['agnet']);
|
|
170
|
-
} catch (e) {
|
|
171
|
-
// Error may or may not be thrown
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const output = consoleOutput.join('');
|
|
175
|
-
// Either shows error or help
|
|
176
|
-
const hasMessage = output.includes('agnet') || output.includes('Unknown') || output.includes('COMMANDS:');
|
|
177
|
-
expect(hasMessage).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('Argument Parsing', () => {
|
|
182
|
-
it('should parse long flags', async () => {
|
|
183
|
-
consoleOutput = [];
|
|
184
|
-
let flagsPassed = false;
|
|
185
|
-
const mockCommand: Command = {
|
|
186
|
-
name: 'testparse',
|
|
187
|
-
description: 'Test command',
|
|
188
|
-
action: async (ctx) => {
|
|
189
|
-
expect(ctx.flags.verbose).toBe(true);
|
|
190
|
-
flagsPassed = true;
|
|
191
|
-
return { success: true };
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
cli['parser'].registerCommand(mockCommand);
|
|
196
|
-
await cli.run(['testparse', '--verbose']);
|
|
197
|
-
expect(flagsPassed).toBe(true);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('should parse short flags', async () => {
|
|
201
|
-
let flagsPassed = false;
|
|
202
|
-
const mockCommand: Command = {
|
|
203
|
-
name: 'testshort',
|
|
204
|
-
description: 'Test command',
|
|
205
|
-
options: [
|
|
206
|
-
{ name: 'debug', short: 'd', type: 'boolean', description: 'Debug mode' }
|
|
207
|
-
],
|
|
208
|
-
action: async (ctx) => {
|
|
209
|
-
// -d is mapped to 'debug' via the command options
|
|
210
|
-
expect(ctx.flags.debug).toBe(true);
|
|
211
|
-
flagsPassed = true;
|
|
212
|
-
return { success: true };
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
cli['parser'].registerCommand(mockCommand);
|
|
217
|
-
await cli.run(['testshort', '-d']);
|
|
218
|
-
expect(flagsPassed).toBe(true);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('should parse flags with values', async () => {
|
|
222
|
-
let flagsPassed = false;
|
|
223
|
-
const mockCommand: Command = {
|
|
224
|
-
name: 'testvalue',
|
|
225
|
-
description: 'Test command',
|
|
226
|
-
action: async (ctx) => {
|
|
227
|
-
expect(ctx.flags.format).toBe('json');
|
|
228
|
-
flagsPassed = true;
|
|
229
|
-
return { success: true };
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
cli['parser'].registerCommand(mockCommand);
|
|
234
|
-
await cli.run(['testvalue', '--format', 'json']);
|
|
235
|
-
expect(flagsPassed).toBe(true);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('should parse flags with equals syntax', async () => {
|
|
239
|
-
let flagsPassed = false;
|
|
240
|
-
const mockCommand: Command = {
|
|
241
|
-
name: 'testequals',
|
|
242
|
-
description: 'Test command',
|
|
243
|
-
action: async (ctx) => {
|
|
244
|
-
expect(ctx.flags.output).toBe('file.txt');
|
|
245
|
-
flagsPassed = true;
|
|
246
|
-
return { success: true };
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
cli['parser'].registerCommand(mockCommand);
|
|
251
|
-
await cli.run(['testequals', '--output=file.txt']);
|
|
252
|
-
expect(flagsPassed).toBe(true);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('should parse multiple flags', async () => {
|
|
256
|
-
let flagsPassed = false;
|
|
257
|
-
const mockCommand: Command = {
|
|
258
|
-
name: 'testmulti',
|
|
259
|
-
description: 'Test command',
|
|
260
|
-
action: async (ctx) => {
|
|
261
|
-
expect(ctx.flags.verbose).toBe(true);
|
|
262
|
-
expect(ctx.flags.format).toBe('json');
|
|
263
|
-
expect(ctx.flags.quiet).toBe(true);
|
|
264
|
-
flagsPassed = true;
|
|
265
|
-
return { success: true };
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
cli['parser'].registerCommand(mockCommand);
|
|
270
|
-
await cli.run(['testmulti', '--verbose', '--format', 'json', '-q']);
|
|
271
|
-
expect(flagsPassed).toBe(true);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('should parse positional arguments', async () => {
|
|
275
|
-
let flagsPassed = false;
|
|
276
|
-
const mockCommand: Command = {
|
|
277
|
-
name: 'testpos',
|
|
278
|
-
description: 'Test command',
|
|
279
|
-
action: async (ctx) => {
|
|
280
|
-
expect(ctx.args).toEqual(['arg1', 'arg2', 'arg3']);
|
|
281
|
-
flagsPassed = true;
|
|
282
|
-
return { success: true };
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
cli['parser'].registerCommand(mockCommand);
|
|
287
|
-
await cli.run(['testpos', 'arg1', 'arg2', 'arg3']);
|
|
288
|
-
expect(flagsPassed).toBe(true);
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('should handle boolean flags correctly', async () => {
|
|
292
|
-
let flagsPassed = false;
|
|
293
|
-
const mockCommand: Command = {
|
|
294
|
-
name: 'testbool',
|
|
295
|
-
description: 'Test command',
|
|
296
|
-
options: [
|
|
297
|
-
{ name: 'force', type: 'boolean', description: 'Force operation' }
|
|
298
|
-
],
|
|
299
|
-
action: async (ctx) => {
|
|
300
|
-
expect(ctx.flags.force).toBe(true);
|
|
301
|
-
flagsPassed = true;
|
|
302
|
-
return { success: true };
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
cli['parser'].registerCommand(mockCommand);
|
|
307
|
-
await cli.run(['testbool', '--force']);
|
|
308
|
-
expect(flagsPassed).toBe(true);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('should handle negated boolean flags', async () => {
|
|
312
|
-
let flagsPassed = false;
|
|
313
|
-
const mockCommand: Command = {
|
|
314
|
-
name: 'testnegate',
|
|
315
|
-
description: 'Test command',
|
|
316
|
-
action: async (ctx) => {
|
|
317
|
-
expect(ctx.flags.color).toBe(false);
|
|
318
|
-
flagsPassed = true;
|
|
319
|
-
return { success: true };
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
cli['parser'].registerCommand(mockCommand);
|
|
324
|
-
await cli.run(['testnegate', '--no-color']);
|
|
325
|
-
expect(flagsPassed).toBe(true);
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
describe('Global Flags', () => {
|
|
330
|
-
it('should handle --quiet flag', async () => {
|
|
331
|
-
let flagsPassed = false;
|
|
332
|
-
const mockCommand: Command = {
|
|
333
|
-
name: 'testquiet',
|
|
334
|
-
description: 'Test command',
|
|
335
|
-
action: async (ctx) => {
|
|
336
|
-
expect(ctx.flags.quiet).toBe(true);
|
|
337
|
-
expect(ctx.interactive).toBe(false);
|
|
338
|
-
flagsPassed = true;
|
|
339
|
-
return { success: true };
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
cli['parser'].registerCommand(mockCommand);
|
|
344
|
-
await cli.run(['testquiet', '--quiet']);
|
|
345
|
-
expect(flagsPassed).toBe(true);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it('should handle --format flag', async () => {
|
|
349
|
-
let flagsPassed = false;
|
|
350
|
-
const mockCommand: Command = {
|
|
351
|
-
name: 'testformat',
|
|
352
|
-
description: 'Test command',
|
|
353
|
-
action: async (ctx) => {
|
|
354
|
-
expect(ctx.flags.format).toBe('json');
|
|
355
|
-
flagsPassed = true;
|
|
356
|
-
return { success: true };
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
cli['parser'].registerCommand(mockCommand);
|
|
361
|
-
await cli.run(['testformat', '--format', 'json']);
|
|
362
|
-
expect(flagsPassed).toBe(true);
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
it('should handle --config flag', async () => {
|
|
366
|
-
let flagsPassed = false;
|
|
367
|
-
const mockCommand: Command = {
|
|
368
|
-
name: 'testconfig',
|
|
369
|
-
description: 'Test command',
|
|
370
|
-
action: async (ctx) => {
|
|
371
|
-
expect(ctx.flags.config).toBe('./custom-config.json');
|
|
372
|
-
flagsPassed = true;
|
|
373
|
-
return { success: true };
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
cli['parser'].registerCommand(mockCommand);
|
|
378
|
-
await cli.run(['testconfig', '--config', './custom-config.json']);
|
|
379
|
-
expect(flagsPassed).toBe(true);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it('should disable color with --no-color', async () => {
|
|
383
|
-
await cli.run(['--no-color', '--help']);
|
|
384
|
-
// Color should be disabled - check output formatter state
|
|
385
|
-
expect(cli['output']['colorEnabled']).toBe(false);
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
describe('Error Handling', () => {
|
|
390
|
-
it('should handle command execution errors', async () => {
|
|
391
|
-
const mockCommand: Command = {
|
|
392
|
-
name: 'testerror',
|
|
393
|
-
description: 'Test command',
|
|
394
|
-
action: async () => {
|
|
395
|
-
throw new Error('Command failed');
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
cli['parser'].registerCommand(mockCommand);
|
|
400
|
-
|
|
401
|
-
try {
|
|
402
|
-
await cli.run(['testerror']);
|
|
403
|
-
} catch (e) {
|
|
404
|
-
expect((e as Error).message).toContain('process.exit');
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// Error messages go to stderr, so check both stdout and stderr
|
|
408
|
-
const allOutput = [...consoleOutput, ...consoleErrorOutput].join('');
|
|
409
|
-
expect(allOutput).toContain('Command failed');
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it('should handle missing required options', async () => {
|
|
413
|
-
const mockCommand: Command = {
|
|
414
|
-
name: 'testreq',
|
|
415
|
-
description: 'Test command',
|
|
416
|
-
options: [
|
|
417
|
-
{ name: 'required-opt', type: 'string', required: true, description: 'Required option' }
|
|
418
|
-
],
|
|
419
|
-
action: async () => ({ success: true })
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
cli['parser'].registerCommand(mockCommand);
|
|
423
|
-
|
|
424
|
-
try {
|
|
425
|
-
await cli.run(['testreq']);
|
|
426
|
-
} catch (e) {
|
|
427
|
-
expect((e as Error).message).toContain('process.exit');
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Error messages go to stderr, so check both stdout and stderr
|
|
431
|
-
const allOutput = [...consoleOutput, ...consoleErrorOutput].join('');
|
|
432
|
-
expect(allOutput).toContain('Required option missing');
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('should show debug info when DEBUG env var is set', async () => {
|
|
436
|
-
process.env.DEBUG = '1';
|
|
437
|
-
|
|
438
|
-
const mockCommand: Command = {
|
|
439
|
-
name: 'testdebug',
|
|
440
|
-
description: 'Test command',
|
|
441
|
-
action: async () => {
|
|
442
|
-
const error = new Error('Test error');
|
|
443
|
-
error.stack = 'Error: Test error\n at test:1:1';
|
|
444
|
-
throw error;
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
cli['parser'].registerCommand(mockCommand);
|
|
449
|
-
|
|
450
|
-
try {
|
|
451
|
-
await cli.run(['testdebug']);
|
|
452
|
-
} catch (e) {
|
|
453
|
-
expect((e as Error).message).toContain('process.exit');
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
const output = consoleOutput.join('');
|
|
457
|
-
expect(output).toContain('Test error');
|
|
458
|
-
|
|
459
|
-
delete process.env.DEBUG;
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
describe('Subcommands', () => {
|
|
464
|
-
it('should execute subcommand', async () => {
|
|
465
|
-
let subcommandExecuted = false;
|
|
466
|
-
|
|
467
|
-
const subcommand: Command = {
|
|
468
|
-
name: 'sub',
|
|
469
|
-
description: 'Subcommand',
|
|
470
|
-
action: async () => {
|
|
471
|
-
subcommandExecuted = true;
|
|
472
|
-
return { success: true };
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
const mainCommand: Command = {
|
|
477
|
-
name: 'maincmd',
|
|
478
|
-
description: 'Main command',
|
|
479
|
-
subcommands: [subcommand]
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
cli['parser'].registerCommand(mainCommand);
|
|
483
|
-
await cli.run(['maincmd', 'sub']);
|
|
484
|
-
|
|
485
|
-
expect(subcommandExecuted).toBe(true);
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
it('should handle subcommand aliases', async () => {
|
|
489
|
-
let executed = false;
|
|
490
|
-
|
|
491
|
-
const subcommand: Command = {
|
|
492
|
-
name: 'list',
|
|
493
|
-
aliases: ['ls'],
|
|
494
|
-
description: 'List items',
|
|
495
|
-
action: async () => {
|
|
496
|
-
executed = true;
|
|
497
|
-
return { success: true };
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
const mainCommand: Command = {
|
|
502
|
-
name: 'mainalias',
|
|
503
|
-
description: 'Main command',
|
|
504
|
-
subcommands: [subcommand]
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
cli['parser'].registerCommand(mainCommand);
|
|
508
|
-
await cli.run(['mainalias', 'ls']);
|
|
509
|
-
|
|
510
|
-
expect(executed).toBe(true);
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
describe('Exit Codes', () => {
|
|
515
|
-
it('should exit with code 0 on success', async () => {
|
|
516
|
-
await cli.run(['--version']);
|
|
517
|
-
// No error thrown = exit code 0
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
it('should exit with code 1 on unknown command', async () => {
|
|
521
|
-
try {
|
|
522
|
-
await cli.run(['unknowntest']);
|
|
523
|
-
} catch (e) {
|
|
524
|
-
expect((e as Error).message).toContain('process.exit: 1');
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
it('should exit with custom code from command result', async () => {
|
|
529
|
-
let actionCalled = false;
|
|
530
|
-
let returnedResult: { success: boolean; exitCode: number } | null = null;
|
|
531
|
-
const mockCommand: Command = {
|
|
532
|
-
name: 'testexitcode',
|
|
533
|
-
description: 'Test command for exit code',
|
|
534
|
-
action: async () => {
|
|
535
|
-
actionCalled = true;
|
|
536
|
-
returnedResult = { success: false, exitCode: 42 };
|
|
537
|
-
return returnedResult;
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
cli['parser'].registerCommand(mockCommand);
|
|
542
|
-
|
|
543
|
-
let errorMessage = '';
|
|
544
|
-
try {
|
|
545
|
-
await cli.run(['testexitcode']);
|
|
546
|
-
} catch (e) {
|
|
547
|
-
errorMessage = (e as Error).message;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// Verify the action was called and returned the expected result
|
|
551
|
-
expect(actionCalled).toBe(true);
|
|
552
|
-
expect(returnedResult).toEqual({ success: false, exitCode: 42 });
|
|
553
|
-
|
|
554
|
-
// Now check exit code
|
|
555
|
-
expect(errorMessage).toContain('process.exit: 42');
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
});
|