@fnndsc/brasa 0.1.0
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/dist/builtins/debug.d.ts +8 -0
- package/dist/builtins/debug.js +39 -0
- package/dist/builtins/debug.js.map +1 -0
- package/dist/builtins/executable.d.ts +22 -0
- package/dist/builtins/executable.js +115 -0
- package/dist/builtins/executable.js.map +1 -0
- package/dist/builtins/fs/cat.d.ts +16 -0
- package/dist/builtins/fs/cat.js +266 -0
- package/dist/builtins/fs/cat.js.map +1 -0
- package/dist/builtins/fs/cd.d.ts +42 -0
- package/dist/builtins/fs/cd.js +193 -0
- package/dist/builtins/fs/cd.js.map +1 -0
- package/dist/builtins/fs/cp.d.ts +10 -0
- package/dist/builtins/fs/cp.js +86 -0
- package/dist/builtins/fs/cp.js.map +1 -0
- package/dist/builtins/fs/download.d.ts +6 -0
- package/dist/builtins/fs/download.js +45 -0
- package/dist/builtins/fs/download.js.map +1 -0
- package/dist/builtins/fs/du.d.ts +58 -0
- package/dist/builtins/fs/du.js +210 -0
- package/dist/builtins/fs/du.js.map +1 -0
- package/dist/builtins/fs/edit.d.ts +7 -0
- package/dist/builtins/fs/edit.js +104 -0
- package/dist/builtins/fs/edit.js.map +1 -0
- package/dist/builtins/fs/ls.d.ts +8 -0
- package/dist/builtins/fs/ls.js +68 -0
- package/dist/builtins/fs/ls.js.map +1 -0
- package/dist/builtins/fs/mkdir.d.ts +9 -0
- package/dist/builtins/fs/mkdir.js +52 -0
- package/dist/builtins/fs/mkdir.js.map +1 -0
- package/dist/builtins/fs/mv.d.ts +10 -0
- package/dist/builtins/fs/mv.js +88 -0
- package/dist/builtins/fs/mv.js.map +1 -0
- package/dist/builtins/fs/pull.args.d.ts +22 -0
- package/dist/builtins/fs/pull.args.js +30 -0
- package/dist/builtins/fs/pull.args.js.map +1 -0
- package/dist/builtins/fs/pull.d.ts +26 -0
- package/dist/builtins/fs/pull.js +445 -0
- package/dist/builtins/fs/pull.js.map +1 -0
- package/dist/builtins/fs/pwd.d.ts +10 -0
- package/dist/builtins/fs/pwd.js +73 -0
- package/dist/builtins/fs/pwd.js.map +1 -0
- package/dist/builtins/fs/rm.d.ts +37 -0
- package/dist/builtins/fs/rm.js +197 -0
- package/dist/builtins/fs/rm.js.map +1 -0
- package/dist/builtins/fs/touch.d.ts +9 -0
- package/dist/builtins/fs/touch.js +76 -0
- package/dist/builtins/fs/touch.js.map +1 -0
- package/dist/builtins/fs/tree.d.ts +15 -0
- package/dist/builtins/fs/tree.js +84 -0
- package/dist/builtins/fs/tree.js.map +1 -0
- package/dist/builtins/fs/upload.d.ts +6 -0
- package/dist/builtins/fs/upload.js +48 -0
- package/dist/builtins/fs/upload.js.map +1 -0
- package/dist/builtins/help.d.ts +74 -0
- package/dist/builtins/help.js +1217 -0
- package/dist/builtins/help.js.map +1 -0
- package/dist/builtins/index.d.ts +45 -0
- package/dist/builtins/index.js +45 -0
- package/dist/builtins/index.js.map +1 -0
- package/dist/builtins/net/connect.d.ts +7 -0
- package/dist/builtins/net/connect.js +42 -0
- package/dist/builtins/net/connect.js.map +1 -0
- package/dist/builtins/net/cubepath.d.ts +18 -0
- package/dist/builtins/net/cubepath.js +102 -0
- package/dist/builtins/net/cubepath.js.map +1 -0
- package/dist/builtins/net/logout.d.ts +6 -0
- package/dist/builtins/net/logout.js +24 -0
- package/dist/builtins/net/logout.js.map +1 -0
- package/dist/builtins/net/pacs.d.ts +24 -0
- package/dist/builtins/net/pacs.js +121 -0
- package/dist/builtins/net/pacs.js.map +1 -0
- package/dist/builtins/net/pacsUtils.d.ts +85 -0
- package/dist/builtins/net/pacsUtils.js +184 -0
- package/dist/builtins/net/pacsUtils.js.map +1 -0
- package/dist/builtins/net/query.d.ts +60 -0
- package/dist/builtins/net/query.js +324 -0
- package/dist/builtins/net/query.js.map +1 -0
- package/dist/builtins/parametersofplugin.d.ts +13 -0
- package/dist/builtins/parametersofplugin.js +43 -0
- package/dist/builtins/parametersofplugin.js.map +1 -0
- package/dist/builtins/pluginExecute.d.ts +27 -0
- package/dist/builtins/pluginExecute.js +165 -0
- package/dist/builtins/pluginExecute.js.map +1 -0
- package/dist/builtins/proc.d.ts +6 -0
- package/dist/builtins/proc.helpers.d.ts +68 -0
- package/dist/builtins/proc.helpers.js +102 -0
- package/dist/builtins/proc.helpers.js.map +1 -0
- package/dist/builtins/proc.js +289 -0
- package/dist/builtins/proc.js.map +1 -0
- package/dist/builtins/res/compute.d.ts +6 -0
- package/dist/builtins/res/compute.js +55 -0
- package/dist/builtins/res/compute.js.map +1 -0
- package/dist/builtins/res/feed.d.ts +6 -0
- package/dist/builtins/res/feed.js +244 -0
- package/dist/builtins/res/feed.js.map +1 -0
- package/dist/builtins/res/feed.notes.d.ts +28 -0
- package/dist/builtins/res/feed.notes.js +24 -0
- package/dist/builtins/res/feed.notes.js.map +1 -0
- package/dist/builtins/res/files.d.ts +18 -0
- package/dist/builtins/res/files.js +85 -0
- package/dist/builtins/res/files.js.map +1 -0
- package/dist/builtins/res/group.d.ts +6 -0
- package/dist/builtins/res/group.js +54 -0
- package/dist/builtins/res/group.js.map +1 -0
- package/dist/builtins/res/pipeline.args.d.ts +22 -0
- package/dist/builtins/res/pipeline.args.js +28 -0
- package/dist/builtins/res/pipeline.args.js.map +1 -0
- package/dist/builtins/res/pipeline.d.ts +20 -0
- package/dist/builtins/res/pipeline.js +252 -0
- package/dist/builtins/res/pipeline.js.map +1 -0
- package/dist/builtins/res/plugin.d.ts +13 -0
- package/dist/builtins/res/plugin.js +140 -0
- package/dist/builtins/res/plugin.js.map +1 -0
- package/dist/builtins/res/plugininstance.d.ts +6 -0
- package/dist/builtins/res/plugininstance.js +53 -0
- package/dist/builtins/res/plugininstance.js.map +1 -0
- package/dist/builtins/res/pluginmeta.d.ts +6 -0
- package/dist/builtins/res/pluginmeta.js +53 -0
- package/dist/builtins/res/pluginmeta.js.map +1 -0
- package/dist/builtins/res/tag.d.ts +6 -0
- package/dist/builtins/res/tag.js +53 -0
- package/dist/builtins/res/tag.js.map +1 -0
- package/dist/builtins/res/workflow.d.ts +6 -0
- package/dist/builtins/res/workflow.js +53 -0
- package/dist/builtins/res/workflow.js.map +1 -0
- package/dist/builtins/store.d.ts +6 -0
- package/dist/builtins/store.js +107 -0
- package/dist/builtins/store.js.map +1 -0
- package/dist/builtins/sys/context.d.ts +6 -0
- package/dist/builtins/sys/context.js +50 -0
- package/dist/builtins/sys/context.js.map +1 -0
- package/dist/builtins/sys/physicalmode.d.ts +8 -0
- package/dist/builtins/sys/physicalmode.js +34 -0
- package/dist/builtins/sys/physicalmode.js.map +1 -0
- package/dist/builtins/sys/timing.d.ts +8 -0
- package/dist/builtins/sys/timing.js +34 -0
- package/dist/builtins/sys/timing.js.map +1 -0
- package/dist/builtins/sys/version.d.ts +15 -0
- package/dist/builtins/sys/version.js +23 -0
- package/dist/builtins/sys/version.js.map +1 -0
- package/dist/builtins/sys/whoami.d.ts +17 -0
- package/dist/builtins/sys/whoami.js +44 -0
- package/dist/builtins/sys/whoami.js.map +1 -0
- package/dist/builtins/utils.d.ts +55 -0
- package/dist/builtins/utils.js +145 -0
- package/dist/builtins/utils.js.map +1 -0
- package/dist/builtins/wildcard.d.ts +26 -0
- package/dist/builtins/wildcard.js +120 -0
- package/dist/builtins/wildcard.js.map +1 -0
- package/dist/command-keys.d.ts +8 -0
- package/dist/command-keys.js +32 -0
- package/dist/command-keys.js.map +1 -0
- package/dist/config/storeConfig.d.ts +57 -0
- package/dist/config/storeConfig.js +78 -0
- package/dist/config/storeConfig.js.map +1 -0
- package/dist/core/chiliDelegate.d.ts +21 -0
- package/dist/core/chiliDelegate.js +32 -0
- package/dist/core/chiliDelegate.js.map +1 -0
- package/dist/core/connect.d.ts +38 -0
- package/dist/core/connect.js +46 -0
- package/dist/core/connect.js.map +1 -0
- package/dist/core/dispatch.d.ts +95 -0
- package/dist/core/dispatch.js +618 -0
- package/dist/core/dispatch.js.map +1 -0
- package/dist/core/engine.d.ts +91 -0
- package/dist/core/engine.js +222 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/preprocess.d.ts +46 -0
- package/dist/core/preprocess.js +146 -0
- package/dist/core/preprocess.js.map +1 -0
- package/dist/core/progress.d.ts +50 -0
- package/dist/core/progress.js +21 -0
- package/dist/core/progress.js.map +1 -0
- package/dist/core/promptContext.d.ts +49 -0
- package/dist/core/promptContext.js +39 -0
- package/dist/core/promptContext.js.map +1 -0
- package/dist/core/question.d.ts +27 -0
- package/dist/core/question.js +33 -0
- package/dist/core/question.js.map +1 -0
- package/dist/core/sink.d.ts +207 -0
- package/dist/core/sink.js +329 -0
- package/dist/core/sink.js.map +1 -0
- package/dist/core/surface.d.ts +172 -0
- package/dist/core/surface.js +105 -0
- package/dist/core/surface.js.map +1 -0
- package/dist/core/version.d.ts +20 -0
- package/dist/core/version.js +82 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/completer/index.d.ts +15 -0
- package/dist/lib/completer/index.js +212 -0
- package/dist/lib/completer/index.js.map +1 -0
- package/dist/lib/completer/pathComplete.helpers.d.ts +22 -0
- package/dist/lib/completer/pathComplete.helpers.js +49 -0
- package/dist/lib/completer/pathComplete.helpers.js.map +1 -0
- package/dist/lib/parser.d.ts +13 -0
- package/dist/lib/parser.js +52 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/pipe.d.ts +11 -0
- package/dist/lib/pipe.js +90 -0
- package/dist/lib/pipe.js.map +1 -0
- package/dist/lib/prefetch.d.ts +25 -0
- package/dist/lib/prefetch.js +64 -0
- package/dist/lib/prefetch.js.map +1 -0
- package/dist/lib/semicolonParser.d.ts +22 -0
- package/dist/lib/semicolonParser.js +53 -0
- package/dist/lib/semicolonParser.js.map +1 -0
- package/dist/lib/spinner.d.ts +23 -0
- package/dist/lib/spinner.js +71 -0
- package/dist/lib/spinner.js.map +1 -0
- package/dist/lib/vfs/providers/static.d.ts +65 -0
- package/dist/lib/vfs/providers/static.js +164 -0
- package/dist/lib/vfs/providers/static.js.map +1 -0
- package/dist/lib/vfs/providers/static_content.d.ts +27 -0
- package/dist/lib/vfs/providers/static_content.js +180 -0
- package/dist/lib/vfs/providers/static_content.js.map +1 -0
- package/dist/lib/vfs/vfs.d.ts +59 -0
- package/dist/lib/vfs/vfs.js +202 -0
- package/dist/lib/vfs/vfs.js.map +1 -0
- package/dist/session/index.d.ts +76 -0
- package/dist/session/index.js +120 -0
- package/dist/session/index.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin cd command.
|
|
3
|
+
* Changes the current working directory, reported as a command envelope.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { session } from '../../session/index.js';
|
|
7
|
+
import { path_resolve, path_resolveLinks, error_stripDebugPrefix } from '../utils.js';
|
|
8
|
+
import { envelope_ok, envelope_error } from '@fnndsc/cumin';
|
|
9
|
+
/**
|
|
10
|
+
* Structural VFS container paths that exist by definition and need no API
|
|
11
|
+
* validation when `cd`-ing into them.
|
|
12
|
+
*/
|
|
13
|
+
const STRUCTURAL_VFS_PATHS = ['/', '/net', '/net/pacs', '/net/pacs/queries', '/proc', '/proc/jobs'];
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes a logical path for VFS comparison by stripping a single trailing
|
|
16
|
+
* slash (except for the root path).
|
|
17
|
+
*
|
|
18
|
+
* @param logicalPath - The resolved logical path.
|
|
19
|
+
* @returns The normalized path.
|
|
20
|
+
*/
|
|
21
|
+
export function vfsPath_normalize(logicalPath) {
|
|
22
|
+
return logicalPath.endsWith('/') && logicalPath.length > 1 ? logicalPath.slice(0, -1) : logicalPath;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reports whether a path is a structural VFS container (always valid).
|
|
26
|
+
*
|
|
27
|
+
* @param cleanPath - The normalized path.
|
|
28
|
+
* @returns True if the path is a known structural VFS container.
|
|
29
|
+
*/
|
|
30
|
+
export function vfsPath_isStructural(cleanPath) {
|
|
31
|
+
return STRUCTURAL_VFS_PATHS.includes(cleanPath);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Verifies if a given FileBrowserFolder object exactly matches the validation path.
|
|
35
|
+
*
|
|
36
|
+
* @param folder - The FileBrowserFolder object to verify.
|
|
37
|
+
* @param validationPath - The path to match against.
|
|
38
|
+
* @returns True if the folder path exactly matches validationPath, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
export function folder_verifyPathMatch(folder, validationPath) {
|
|
41
|
+
if (!folder) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const folderPath = folder.data?.path || folder.path || '';
|
|
45
|
+
// Normalize both by removing all leading and trailing slashes to be robust against API inconsistencies
|
|
46
|
+
const cleanFolder = folderPath.replace(/^\/+|\/+$/g, '');
|
|
47
|
+
const cleanValidation = validationPath.replace(/^\/+|\/+$/g, '');
|
|
48
|
+
return cleanFolder === cleanValidation;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Builds the success envelope for a completed directory change.
|
|
52
|
+
*
|
|
53
|
+
* @param newCwd - The working directory that is now current.
|
|
54
|
+
* @param rendered - Any stdout text (debug traces) produced along the way.
|
|
55
|
+
* @returns An ok envelope carrying the fs.cwd model.
|
|
56
|
+
*/
|
|
57
|
+
function cdSuccess_envelope(newCwd, rendered) {
|
|
58
|
+
return envelope_ok(rendered, { kind: 'fs.cwd', data: { path: newCwd } });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Handles `cd` into a virtual (VFS) path: structural containers are accepted
|
|
62
|
+
* directly, deeper VFS paths are validated and their listing cached.
|
|
63
|
+
*
|
|
64
|
+
* @param cleanPath - The normalized virtual path.
|
|
65
|
+
* @param pathArg - The original user-supplied path (for error messages).
|
|
66
|
+
* @returns The command envelope for the attempt.
|
|
67
|
+
*/
|
|
68
|
+
async function cdVirtual_handle(cleanPath, pathArg) {
|
|
69
|
+
if (vfsPath_isStructural(cleanPath)) {
|
|
70
|
+
await session.setCWD(cleanPath);
|
|
71
|
+
return cdSuccess_envelope(cleanPath, '');
|
|
72
|
+
}
|
|
73
|
+
// For deeper VFS paths (e.g. /net/pacs/queries/<id>), validate and cache the
|
|
74
|
+
// result so a subsequent `ls` doesn't need to re-fetch.
|
|
75
|
+
const { vfsDispatcher } = await import('@fnndsc/salsa');
|
|
76
|
+
const listResult = await vfsDispatcher.list(cleanPath);
|
|
77
|
+
if (!listResult.ok) {
|
|
78
|
+
const { errorStack } = await import('@fnndsc/cumin');
|
|
79
|
+
const lastError = errorStack.stack_pop();
|
|
80
|
+
const detail = lastError ? error_stripDebugPrefix(lastError.message) : 'No such file or directory';
|
|
81
|
+
return envelope_error('', undefined, `${chalk.red(`cd: ${pathArg}: ${detail}`)}\n`);
|
|
82
|
+
}
|
|
83
|
+
const { listCache_get } = await import('@fnndsc/cumin');
|
|
84
|
+
listCache_get().cache_set(cleanPath, listResult.value);
|
|
85
|
+
await session.setCWD(cleanPath);
|
|
86
|
+
return cdSuccess_envelope(cleanPath, '');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Handles `cd` into a real (API-backed) ChRIS folder: resolves the validation
|
|
90
|
+
* path, then confirms the folder exists with an exact path match before setting
|
|
91
|
+
* the working directory.
|
|
92
|
+
*
|
|
93
|
+
* @param logicalPath - The resolved logical path.
|
|
94
|
+
* @param pathArg - The original user-supplied path (for error messages).
|
|
95
|
+
* @returns The command envelope for the attempt.
|
|
96
|
+
*/
|
|
97
|
+
async function cdReal_handle(logicalPath, pathArg) {
|
|
98
|
+
const client = await session.connection.client_get();
|
|
99
|
+
if (!client) {
|
|
100
|
+
return envelope_error('', undefined, `${chalk.red('Not connected to ChRIS.')}\n`);
|
|
101
|
+
}
|
|
102
|
+
const debugEnabled = session.connection.config?.debug === true;
|
|
103
|
+
let rendered = '';
|
|
104
|
+
let validationPath;
|
|
105
|
+
if (session.physicalMode_get()) {
|
|
106
|
+
validationPath = await path_resolveLinks(logicalPath);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const { logical_toPhysical } = await import('@fnndsc/chili/utils');
|
|
110
|
+
const physicalResult = await logical_toPhysical(logicalPath);
|
|
111
|
+
if (!physicalResult.ok) {
|
|
112
|
+
let renderedErr = `${chalk.red(`cd: ${pathArg}: No such file or directory`)}\n`;
|
|
113
|
+
if (debugEnabled) {
|
|
114
|
+
renderedErr += `${chalk.gray(` Logical path: ${logicalPath}`)}\n`;
|
|
115
|
+
}
|
|
116
|
+
return envelope_error('', undefined, renderedErr);
|
|
117
|
+
}
|
|
118
|
+
validationPath = physicalResult.value;
|
|
119
|
+
}
|
|
120
|
+
if (debugEnabled) {
|
|
121
|
+
rendered += `${chalk.gray(`cd: ${pathArg} → logical: ${logicalPath} → validation: ${validationPath}`)}\n`;
|
|
122
|
+
}
|
|
123
|
+
const cwdPath = session.physicalMode_get() ? validationPath : logicalPath;
|
|
124
|
+
const currentCwd = await session.getCWD();
|
|
125
|
+
if (currentCwd === cwdPath) {
|
|
126
|
+
if (debugEnabled) {
|
|
127
|
+
rendered += `${chalk.gray(` Already in target directory, skipping validation`)}\n`;
|
|
128
|
+
}
|
|
129
|
+
return cdSuccess_envelope(cwdPath, rendered);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const folder = (await client.getFileBrowserFolderByPath(validationPath));
|
|
133
|
+
if (folder_verifyPathMatch(folder, validationPath)) {
|
|
134
|
+
await session.setCWD(cwdPath);
|
|
135
|
+
return cdSuccess_envelope(cwdPath, rendered);
|
|
136
|
+
}
|
|
137
|
+
let renderedErr = `${chalk.red(`cd: ${pathArg}: No such file or directory`)}\n`;
|
|
138
|
+
if (debugEnabled) {
|
|
139
|
+
if (!folder) {
|
|
140
|
+
renderedErr += `${chalk.gray(` API returned null for path: ${validationPath}`)}\n`;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const folderPath = folder.data?.path || folder.path;
|
|
144
|
+
renderedErr += `${chalk.gray(` API returned mismatched folder path: ${folderPath} (expected: ${validationPath})`)}\n`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const envelope = envelope_error(rendered, undefined, renderedErr);
|
|
148
|
+
return envelope;
|
|
149
|
+
}
|
|
150
|
+
catch (apiError) {
|
|
151
|
+
let renderedErr = `${chalk.red(`cd: ${pathArg}: No such file or directory`)}\n`;
|
|
152
|
+
if (debugEnabled) {
|
|
153
|
+
const msg = apiError instanceof Error ? apiError.message : String(apiError);
|
|
154
|
+
renderedErr += `${chalk.gray(` API error: ${msg}`)}\n`;
|
|
155
|
+
}
|
|
156
|
+
return envelope_error(rendered, undefined, renderedErr);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Changes the current working directory in the ChRIS filesystem context.
|
|
161
|
+
* Validates the existence of the target path before setting it.
|
|
162
|
+
*
|
|
163
|
+
* @param args - An array containing the target path as the first element.
|
|
164
|
+
* @returns An envelope carrying the new working directory on success.
|
|
165
|
+
*/
|
|
166
|
+
export async function builtin_cd(args) {
|
|
167
|
+
const pathArg = args.length > 0 ? args.join(' ') : undefined;
|
|
168
|
+
// 'cd' with no args goes to home
|
|
169
|
+
if (!pathArg) {
|
|
170
|
+
return builtin_cd(['~']);
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const logicalPath = await path_resolve(pathArg);
|
|
174
|
+
const { vfsDispatcher } = await import('@fnndsc/salsa');
|
|
175
|
+
const cleanPath = vfsPath_normalize(logicalPath);
|
|
176
|
+
// Treat the path as virtual if it is, or is a parent of, any registered
|
|
177
|
+
// provider prefix (e.g. /proc is parent of /proc/feeds).
|
|
178
|
+
const isParentOfVfs = vfsDispatcher.providers_get().some((p) => p.prefix.startsWith(cleanPath + '/'));
|
|
179
|
+
const isVirtual = cleanPath === '/' ||
|
|
180
|
+
cleanPath === '/net' ||
|
|
181
|
+
isParentOfVfs ||
|
|
182
|
+
vfsDispatcher.provider_get(cleanPath).prefix !== '';
|
|
183
|
+
if (isVirtual) {
|
|
184
|
+
return cdVirtual_handle(cleanPath, pathArg);
|
|
185
|
+
}
|
|
186
|
+
return cdReal_handle(logicalPath, pathArg);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
190
|
+
return envelope_error('', undefined, `${chalk.red(`Failed to cd: ${msg}`)}\n`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=cd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cd.js","sourceRoot":"","sources":["../../../src/builtins/fs/cd.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAc5D;;;GAGG;AACH,MAAM,oBAAoB,GAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAE9G;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,OAAO,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;AACtG,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH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@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommandEnvelope } from '@fnndsc/cumin';
|
|
2
|
+
/**
|
|
3
|
+
* Copies a file or directory.
|
|
4
|
+
* Supports multiple sources when destination is a directory.
|
|
5
|
+
*
|
|
6
|
+
* @param args - [flags, src1, src2, ..., dest]
|
|
7
|
+
* @returns An envelope whose rendered text reports progress and results and
|
|
8
|
+
* whose model carries per-source outcomes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function builtin_cp(args: string[]): Promise<CommandEnvelope>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin cp command.
|
|
3
|
+
* Copies files or directories, reported as a command envelope.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { listCache_get, envelope_ok, envelope_error } from '@fnndsc/cumin';
|
|
8
|
+
import { commandArgs_process, path_resolve } from '../utils.js';
|
|
9
|
+
import { files_cp as chefs_cp_cmd } from '@fnndsc/chili/commands/fs/cp.js';
|
|
10
|
+
import { cp_render } from '@fnndsc/chili/views/fs.js';
|
|
11
|
+
/**
|
|
12
|
+
* Copies a file or directory.
|
|
13
|
+
* Supports multiple sources when destination is a directory.
|
|
14
|
+
*
|
|
15
|
+
* @param args - [flags, src1, src2, ..., dest]
|
|
16
|
+
* @returns An envelope whose rendered text reports progress and results and
|
|
17
|
+
* whose model carries per-source outcomes.
|
|
18
|
+
*/
|
|
19
|
+
export async function builtin_cp(args) {
|
|
20
|
+
const parsed = commandArgs_process(args);
|
|
21
|
+
const pathArgs = parsed._;
|
|
22
|
+
if (pathArgs.length < 2) {
|
|
23
|
+
return envelope_error(`${chalk.red('Usage: cp [-r] <source...> <dest>')}\n`);
|
|
24
|
+
}
|
|
25
|
+
const recursive = !!parsed['r'] || !!parsed['recursive'];
|
|
26
|
+
// Last arg is destination, all others are sources
|
|
27
|
+
const dest = pathArgs[pathArgs.length - 1];
|
|
28
|
+
const sources = pathArgs.slice(0, -1);
|
|
29
|
+
const destPath = await path_resolve(dest);
|
|
30
|
+
const listCache = listCache_get();
|
|
31
|
+
let successCount = 0;
|
|
32
|
+
let failCount = 0;
|
|
33
|
+
let rendered = '';
|
|
34
|
+
let renderedErr = '';
|
|
35
|
+
const outcomes = [];
|
|
36
|
+
for (const src of sources) {
|
|
37
|
+
try {
|
|
38
|
+
const srcPath = await path_resolve(src);
|
|
39
|
+
// For multiple sources, show which file we're copying
|
|
40
|
+
if (sources.length > 1) {
|
|
41
|
+
rendered += `${chalk.gray(`Copying ${srcPath}...`)}\n`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
rendered += `Copying ${srcPath} to ${destPath}...\n`;
|
|
45
|
+
}
|
|
46
|
+
const success = await chefs_cp_cmd(srcPath, destPath, { recursive });
|
|
47
|
+
if (sources.length === 1) {
|
|
48
|
+
rendered += `${cp_render(srcPath, destPath, success)}\n`;
|
|
49
|
+
}
|
|
50
|
+
outcomes.push({ source: srcPath, copied: success });
|
|
51
|
+
if (success) {
|
|
52
|
+
successCount++;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
failCount++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
60
|
+
renderedErr += `${chalk.red(`cp: ${src}: ${msg}`)}\n`;
|
|
61
|
+
outcomes.push({ source: src, copied: false });
|
|
62
|
+
failCount++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Invalidate destination directory (always, since files copied into it)
|
|
66
|
+
listCache.cache_invalidate(destPath);
|
|
67
|
+
const destParent = path.posix.dirname(destPath);
|
|
68
|
+
listCache.cache_invalidate(destParent);
|
|
69
|
+
// Summary for multiple files
|
|
70
|
+
if (sources.length > 1) {
|
|
71
|
+
if (failCount === 0) {
|
|
72
|
+
rendered += `${chalk.green(`✓ Copied ${successCount} file(s) to ${destPath}`)}\n`;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
rendered += `${chalk.yellow(`⚠ Copied ${successCount} file(s), ${failCount} failed`)}\n`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const modelData = { dest: destPath, outcomes, copied: successCount, failed: failCount };
|
|
79
|
+
if (failCount > 0) {
|
|
80
|
+
const envelope = envelope_error(rendered, undefined, renderedErr || undefined);
|
|
81
|
+
envelope.model = { kind: 'fs.cp', data: modelData };
|
|
82
|
+
return envelope;
|
|
83
|
+
}
|
|
84
|
+
return envelope_ok(rendered, { kind: 'fs.cp', data: modelData });
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=cp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cp.js","sourceRoot":"","sources":["../../../src/builtins/fs/cp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAmB,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5F,OAAO,EAAc,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAgBtD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAc;IAC7C,MAAM,MAAM,GAAe,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAa,MAAM,CAAC,CAAa,CAAC;IAEhD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,cAAc,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,mCAAmC,CAAC,IAAI,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,SAAS,GAAY,CAAC,CAAC,M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,CAAC;IACrG,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,QAAQ,GAAoB,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,IAAI,SAAS,CAAC,CAAC;QAChG,QAAQ,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,WAAW,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin download command.
|
|
3
|
+
* Downloads files from ChRIS to the local filesystem with progress.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { path_resolve } from '../utils.js';
|
|
8
|
+
import { files_downloadWithProgress as chefs_download_cmd, bytes_format } from '@fnndsc/chili/commands/fs/download.js';
|
|
9
|
+
import { sink_get } from '../../core/sink.js';
|
|
10
|
+
/**
|
|
11
|
+
* Downloads a remote ChRIS file or directory to the local filesystem.
|
|
12
|
+
*
|
|
13
|
+
* @param args - [remotePath, localPath] plus optional -f/--force to overwrite.
|
|
14
|
+
*/
|
|
15
|
+
export async function builtin_download(args) {
|
|
16
|
+
const force = args.includes('-f') || args.includes('--force');
|
|
17
|
+
const cleanArgs = args.filter(arg => arg !== '-f' && arg !== '--force');
|
|
18
|
+
if (cleanArgs.length < 2) {
|
|
19
|
+
console.log(chalk.red('Usage: download <remote_path> <local_path> [-f|--force]'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const remotePathArg = cleanArgs[0];
|
|
23
|
+
const localPathArg = cleanArgs[1];
|
|
24
|
+
const targetRemote = await path_resolve(remotePathArg);
|
|
25
|
+
const targetLocal = path.resolve(localPathArg);
|
|
26
|
+
try {
|
|
27
|
+
const summary = await chefs_download_cmd(targetRemote, targetLocal, {
|
|
28
|
+
force,
|
|
29
|
+
onProgress: event => sink_get().progress_write(event),
|
|
30
|
+
});
|
|
31
|
+
console.log('');
|
|
32
|
+
if (summary.failedCount === 0) {
|
|
33
|
+
console.log(chalk.green(`✓ Successfully downloaded ${summary.transferredCount} file(s)`));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(chalk.yellow(`⚠ Downloaded ${summary.transferredCount} file(s), ${summary.failedCount} failed`));
|
|
37
|
+
}
|
|
38
|
+
console.log(chalk.gray(` Total: ${bytes_format(summary.transferSize)} in ${summary.duration.toFixed(1)}s (${bytes_format(summary.speed)}/s)`));
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
42
|
+
console.error(chalk.red(`Download error: ${msg}`));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../../src/builtins/fs/download.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,0BAA0B,IAAI,kBAAkB,EAEhD,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAc;IACnD,MAAM,KAAK,GAAY,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACvE,MAAM,SAAS,GAAa,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC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AC,CAAC,CAAC;IAClJ,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QACpB,MAAM,GAAG,GAAW,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ParsedArgs } from '../utils.js';
|
|
2
|
+
import { type ScanRecord } from '@fnndsc/chili/path/pathCommand.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parsed flags controlling `du` output.
|
|
5
|
+
*/
|
|
6
|
+
export interface DuOptions {
|
|
7
|
+
humanReadable: boolean;
|
|
8
|
+
summarize: boolean;
|
|
9
|
+
showAll: boolean;
|
|
10
|
+
showTotal: boolean;
|
|
11
|
+
separateDirs: boolean;
|
|
12
|
+
maxDepth: number | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Formats a byte count for `du` output: human-readable string or KB integer,
|
|
16
|
+
* right-padded to 12 characters for column alignment.
|
|
17
|
+
*
|
|
18
|
+
* @param bytes - Raw byte count.
|
|
19
|
+
* @param humanReadable - If true, format as human-readable (e.g. `1.2M`).
|
|
20
|
+
* @returns Right-aligned size string.
|
|
21
|
+
*/
|
|
22
|
+
export declare function duSize_format(bytes: number, humanReadable: boolean): string;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts `du` flags from parsed command arguments.
|
|
25
|
+
*
|
|
26
|
+
* @param parsed - The parsed command arguments.
|
|
27
|
+
* @returns The resolved du options.
|
|
28
|
+
*/
|
|
29
|
+
export declare function duOptions_parse(parsed: ParsedArgs): DuOptions;
|
|
30
|
+
/**
|
|
31
|
+
* Accumulates per-directory sizes from a scan result, attributing each file's
|
|
32
|
+
* size to its ancestor directories up to (and including) the target path.
|
|
33
|
+
*
|
|
34
|
+
* @param scanResult - The recursive scan result.
|
|
35
|
+
* @param targetPath - The directory being measured.
|
|
36
|
+
* @param opts - The du options (separateDirs / showAll affect attribution).
|
|
37
|
+
* @returns A map of directory path to accumulated size.
|
|
38
|
+
*/
|
|
39
|
+
export declare function dirSizes_compute(scanResult: ScanRecord, targetPath: string, opts: DuOptions): Map<string, number>;
|
|
40
|
+
/**
|
|
41
|
+
* Displays disk usage statistics for ChRIS filesystem directories.
|
|
42
|
+
* Mimics standard Linux du command behavior and flags.
|
|
43
|
+
* Uses chili's scan_do machinery for recursive filesystem traversal.
|
|
44
|
+
*
|
|
45
|
+
* @param args - Command line arguments (optional path and flags).
|
|
46
|
+
* @returns A Promise that resolves when disk usage is displayed.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```
|
|
50
|
+
* du # Disk usage of current directory
|
|
51
|
+
* du -h # Human-readable sizes
|
|
52
|
+
* du -s /home/user/data # Summary only
|
|
53
|
+
* du -a # Show all files, not just directories
|
|
54
|
+
* du -c # Show grand total
|
|
55
|
+
* du -d 2 # Max depth of 2 levels
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function builtin_du(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin du command.
|
|
3
|
+
* Displays disk usage.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { commandArgs_process, path_resolve } from '../utils.js';
|
|
8
|
+
import { session } from '../../session/index.js';
|
|
9
|
+
import { vfs } from '../../lib/vfs/vfs.js';
|
|
10
|
+
import { spinner } from '../../lib/spinner.js';
|
|
11
|
+
import { scan_do } from '@fnndsc/chili/path/pathCommand.js';
|
|
12
|
+
import { bytes_format } from '@fnndsc/chili/commands/fs/upload.js';
|
|
13
|
+
/**
|
|
14
|
+
* Formats a byte count for `du` output: human-readable string or KB integer,
|
|
15
|
+
* right-padded to 12 characters for column alignment.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - Raw byte count.
|
|
18
|
+
* @param humanReadable - If true, format as human-readable (e.g. `1.2M`).
|
|
19
|
+
* @returns Right-aligned size string.
|
|
20
|
+
*/
|
|
21
|
+
export function duSize_format(bytes, humanReadable) {
|
|
22
|
+
const formatted = humanReadable
|
|
23
|
+
? bytes_format(bytes)
|
|
24
|
+
: Math.ceil(bytes / 1024).toString();
|
|
25
|
+
return formatted.padStart(12, ' ');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extracts `du` flags from parsed command arguments.
|
|
29
|
+
*
|
|
30
|
+
* @param parsed - The parsed command arguments.
|
|
31
|
+
* @returns The resolved du options.
|
|
32
|
+
*/
|
|
33
|
+
export function duOptions_parse(parsed) {
|
|
34
|
+
const maxDepth = parsed['d']
|
|
35
|
+
? parseInt(String(parsed['d']), 10)
|
|
36
|
+
: parsed['max-depth']
|
|
37
|
+
? parseInt(String(parsed['max-depth']), 10)
|
|
38
|
+
: undefined;
|
|
39
|
+
return {
|
|
40
|
+
humanReadable: !!parsed['h'] || !!parsed['human-readable'],
|
|
41
|
+
summarize: !!parsed['s'] || !!parsed['summarize'],
|
|
42
|
+
showAll: !!parsed['a'] || !!parsed['all'],
|
|
43
|
+
showTotal: !!parsed['c'] || !!parsed['total'],
|
|
44
|
+
separateDirs: !!parsed['S'] || !!parsed['separate-dirs'],
|
|
45
|
+
maxDepth,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolves whether a target path is a directory or a file (with size).
|
|
50
|
+
*
|
|
51
|
+
* @param targetPath - The resolved ChRIS path to stat.
|
|
52
|
+
* @returns A TargetStat on success, or an error message string on failure.
|
|
53
|
+
*/
|
|
54
|
+
async function targetStat_resolve(targetPath) {
|
|
55
|
+
try {
|
|
56
|
+
const result = await vfs.data_get(targetPath, { directory: true });
|
|
57
|
+
if (result.ok && result.value.length > 0) {
|
|
58
|
+
const item = result.value[0];
|
|
59
|
+
if (item.type === 'dir' || item.type === 'vfs') {
|
|
60
|
+
return { isDirectory: true, fileSize: 0 };
|
|
61
|
+
}
|
|
62
|
+
return { isDirectory: false, fileSize: item.size || 0 };
|
|
63
|
+
}
|
|
64
|
+
return `du: cannot access '${targetPath}': No such file or directory`;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return `du: cannot access '${targetPath}': ${e}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Accumulates per-directory sizes from a scan result, attributing each file's
|
|
72
|
+
* size to its ancestor directories up to (and including) the target path.
|
|
73
|
+
*
|
|
74
|
+
* @param scanResult - The recursive scan result.
|
|
75
|
+
* @param targetPath - The directory being measured.
|
|
76
|
+
* @param opts - The du options (separateDirs / showAll affect attribution).
|
|
77
|
+
* @returns A map of directory path to accumulated size.
|
|
78
|
+
*/
|
|
79
|
+
export function dirSizes_compute(scanResult, targetPath, opts) {
|
|
80
|
+
const dirSizes = new Map();
|
|
81
|
+
scanResult.fileInfo.forEach((fileInfo) => {
|
|
82
|
+
const filePath = fileInfo.chrisPath;
|
|
83
|
+
const fSize = fileInfo.size;
|
|
84
|
+
if (fileInfo.isDirectory) {
|
|
85
|
+
if (!dirSizes.has(filePath)) {
|
|
86
|
+
dirSizes.set(filePath, 0);
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// File: add to its parent directory and all ancestor directories,
|
|
91
|
+
// but only up to the targetPath currently being scanned.
|
|
92
|
+
let currentPath = path.posix.dirname(filePath);
|
|
93
|
+
while (currentPath && currentPath.startsWith(targetPath)) {
|
|
94
|
+
const currentSize = dirSizes.get(currentPath) || 0;
|
|
95
|
+
dirSizes.set(currentPath, currentSize + fSize);
|
|
96
|
+
if (currentPath === targetPath)
|
|
97
|
+
break;
|
|
98
|
+
if (opts.separateDirs)
|
|
99
|
+
break;
|
|
100
|
+
currentPath = path.posix.dirname(currentPath);
|
|
101
|
+
}
|
|
102
|
+
if (opts.showAll) {
|
|
103
|
+
dirSizes.set(filePath, fSize);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
// Ensure the target directory itself exists in the map with total size.
|
|
107
|
+
if (!dirSizes.has(targetPath)) {
|
|
108
|
+
dirSizes.set(targetPath, scanResult.totalSize);
|
|
109
|
+
}
|
|
110
|
+
return dirSizes;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Renders accumulated directory sizes to stdout, honouring summary and
|
|
114
|
+
* max-depth options.
|
|
115
|
+
*
|
|
116
|
+
* @param dirSizes - Map of directory path to size.
|
|
117
|
+
* @param targetPath - The directory being measured.
|
|
118
|
+
* @param opts - The du options.
|
|
119
|
+
*/
|
|
120
|
+
function dirUsage_render(dirSizes, targetPath, opts) {
|
|
121
|
+
if (opts.summarize) {
|
|
122
|
+
const size = dirSizes.get(targetPath) || 0;
|
|
123
|
+
console.log(`${duSize_format(size, opts.humanReadable)}\t${targetPath}`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const entries = Array.from(dirSizes.entries());
|
|
127
|
+
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
128
|
+
for (const [dirPath, dirSize] of entries) {
|
|
129
|
+
if (opts.maxDepth !== undefined) {
|
|
130
|
+
const rel = path.posix.relative(targetPath, dirPath);
|
|
131
|
+
const depth = rel === '' ? 0 : rel.split('/').length;
|
|
132
|
+
if (depth > opts.maxDepth)
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
console.log(`${duSize_format(dirSize, opts.humanReadable)}\t${dirPath}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Displays disk usage statistics for ChRIS filesystem directories.
|
|
140
|
+
* Mimics standard Linux du command behavior and flags.
|
|
141
|
+
* Uses chili's scan_do machinery for recursive filesystem traversal.
|
|
142
|
+
*
|
|
143
|
+
* @param args - Command line arguments (optional path and flags).
|
|
144
|
+
* @returns A Promise that resolves when disk usage is displayed.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```
|
|
148
|
+
* du # Disk usage of current directory
|
|
149
|
+
* du -h # Human-readable sizes
|
|
150
|
+
* du -s /home/user/data # Summary only
|
|
151
|
+
* du -a # Show all files, not just directories
|
|
152
|
+
* du -c # Show grand total
|
|
153
|
+
* du -d 2 # Max depth of 2 levels
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export async function builtin_du(args) {
|
|
157
|
+
const parsed = commandArgs_process(args);
|
|
158
|
+
const opts = duOptions_parse(parsed);
|
|
159
|
+
const pathArgs = parsed._;
|
|
160
|
+
const originalFolder = await session.getCWD();
|
|
161
|
+
const rawTargets = pathArgs.length > 0 ? pathArgs : ['.'];
|
|
162
|
+
const resolvedTargets = [];
|
|
163
|
+
for (const raw of rawTargets) {
|
|
164
|
+
resolvedTargets.push(await path_resolve(raw));
|
|
165
|
+
}
|
|
166
|
+
let grandTotal = 0;
|
|
167
|
+
try {
|
|
168
|
+
for (const targetPath of resolvedTargets) {
|
|
169
|
+
const argLabel = path.basename(targetPath);
|
|
170
|
+
spinner.start(`Scanning ${argLabel}...`);
|
|
171
|
+
const stat = await targetStat_resolve(targetPath);
|
|
172
|
+
if (typeof stat === 'string') {
|
|
173
|
+
spinner.stop();
|
|
174
|
+
console.error(chalk.red(stat));
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!stat.isDirectory) {
|
|
178
|
+
grandTotal += stat.fileSize;
|
|
179
|
+
spinner.stop();
|
|
180
|
+
console.log(`${duSize_format(stat.fileSize, opts.humanReadable)}\t${targetPath}`);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
await session.setCWD(targetPath);
|
|
184
|
+
const scanOptions = {
|
|
185
|
+
silent: true,
|
|
186
|
+
tree: false,
|
|
187
|
+
follow: false,
|
|
188
|
+
dirsOnly: false,
|
|
189
|
+
};
|
|
190
|
+
const scanResult = await scan_do(scanOptions);
|
|
191
|
+
await session.setCWD(originalFolder);
|
|
192
|
+
if (!scanResult) {
|
|
193
|
+
spinner.stop();
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const dirSizes = dirSizes_compute(scanResult, targetPath, opts);
|
|
197
|
+
grandTotal += scanResult.totalSize;
|
|
198
|
+
spinner.stop();
|
|
199
|
+
dirUsage_render(dirSizes, targetPath, opts);
|
|
200
|
+
}
|
|
201
|
+
if (opts.showTotal && rawTargets.length > 0) {
|
|
202
|
+
console.log(`${duSize_format(grandTotal, opts.humanReadable)}\ttotal`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
spinner.stop();
|
|
207
|
+
await session.setCWD(originalFolder);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=du.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"du.js","sourceRoot":"","sources":["../../../src/builtins/fs/du.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAc,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAiC,MAAM,mCAAmC,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAwBnE;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,aAAsB;IACjE,MAAM,SAAS,GAAW,aAAa;QACrC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC,IAAI,CAAC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