mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Let ls work on absolute paths
This commit is contained in:
2 files changed
+16
-9
No files matched your search
@@ -131,10 +131,19 @@ describe('LsCommand', () => {
|
|||||||
expect(result.stderr).toContain('No such file or directory');
|
expect(result.stderr).toContain('No such file or directory');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject absolute paths', async () => {
|
it('should handle absolute paths', async () => {
|
||||||
|
vi.mocked(mockFS.stat).mockResolvedValue({
|
||||||
|
isDirectory: () => true,
|
||||||
|
isFile: () => false,
|
||||||
|
});
|
||||||
|
vi.mocked(mockFS.readdir).mockResolvedValue([
|
||||||
|
{ name: 'file1.txt', isDirectory: () => false, isFile: () => true },
|
||||||
|
]);
|
||||||
|
|
||||||
const result = await lsCommand.execute(['/absolute/path'], testCwd);
|
const result = await lsCommand.execute(['/absolute/path'], testCwd);
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.stderr).toContain('absolute paths are not supported');
|
expect(mockFS.stat).toHaveBeenCalledWith('/absolute/path');
|
||||||
|
expect(result.stdout).toContain('file1.txt');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -28,12 +28,10 @@ export class LsCommand implements ShellCommand {
|
|||||||
|
|
||||||
for (const path of targetPaths) {
|
for (const path of targetPaths) {
|
||||||
try {
|
try {
|
||||||
// Handle absolute paths
|
// Determine the absolute path
|
||||||
if (path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(path)) {
|
const absolutePath = path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(path)
|
||||||
return createErrorResult(`${this.name}: absolute paths are not supported: ${path}`);
|
? path // Already absolute
|
||||||
}
|
: join(cwd, path); // Make relative path absolute
|
||||||
|
|
||||||
const absolutePath = join(cwd, path);
|
|
||||||
const stats = await this.fs.stat(absolutePath);
|
const stats = await this.fs.stat(absolutePath);
|
||||||
|
|
||||||
if (stats.isFile()) {
|
if (stats.isFile()) {
|
||||||
|
|||||||
Reference in new issue
Block a user