@fnndsc/chell 4.2.8
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/LICENSE +21 -0
- package/README.md +325 -0
- package/dist/builtins/debug.d.ts +6 -0
- package/dist/builtins/debug.js +47 -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 +249 -0
- package/dist/builtins/fs/cat.js.map +1 -0
- package/dist/builtins/fs/cd.d.ts +41 -0
- package/dist/builtins/fs/cd.js +178 -0
- package/dist/builtins/fs/cd.js.map +1 -0
- package/dist/builtins/fs/cp.d.ts +7 -0
- package/dist/builtins/fs/cp.js +73 -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 +41 -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 +86 -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 +6 -0
- package/dist/builtins/fs/mkdir.js +38 -0
- package/dist/builtins/fs/mkdir.js.map +1 -0
- package/dist/builtins/fs/mv.d.ts +7 -0
- package/dist/builtins/fs/mv.js +75 -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 +413 -0
- package/dist/builtins/fs/pull.js.map +1 -0
- package/dist/builtins/fs/pwd.d.ts +7 -0
- package/dist/builtins/fs/pwd.js +75 -0
- package/dist/builtins/fs/pwd.js.map +1 -0
- package/dist/builtins/fs/rm.d.ts +31 -0
- package/dist/builtins/fs/rm.js +148 -0
- package/dist/builtins/fs/rm.js.map +1 -0
- package/dist/builtins/fs/touch.d.ts +6 -0
- package/dist/builtins/fs/touch.js +64 -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 +45 -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 +304 -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 +108 -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 +6 -0
- package/dist/builtins/sys/physicalmode.js +41 -0
- package/dist/builtins/sys/physicalmode.js.map +1 -0
- package/dist/builtins/sys/prompt.d.ts +13 -0
- package/dist/builtins/sys/prompt.helpers.d.ts +31 -0
- package/dist/builtins/sys/prompt.helpers.js +36 -0
- package/dist/builtins/sys/prompt.helpers.js.map +1 -0
- package/dist/builtins/sys/prompt.js +182 -0
- package/dist/builtins/sys/prompt.js.map +1 -0
- package/dist/builtins/sys/timing.d.ts +6 -0
- package/dist/builtins/sys/timing.js +41 -0
- package/dist/builtins/sys/timing.js.map +1 -0
- package/dist/builtins/sys/whoami.d.ts +12 -0
- package/dist/builtins/sys/whoami.js +37 -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/chell.d.ts +16 -0
- package/dist/chell.js +1193 -0
- package/dist/chell.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/settings.d.ts +39 -0
- package/dist/config/settings.js +93 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/core/bootFlags.d.ts +32 -0
- package/dist/core/bootFlags.js +25 -0
- package/dist/core/bootFlags.js.map +1 -0
- package/dist/core/cli.d.ts +58 -0
- package/dist/core/cli.js +251 -0
- package/dist/core/cli.js.map +1 -0
- package/dist/core/prompt/index.d.ts +80 -0
- package/dist/core/prompt/index.js +29 -0
- package/dist/core/prompt/index.js.map +1 -0
- package/dist/core/prompt/theme_default.d.ts +19 -0
- package/dist/core/prompt/theme_default.js +47 -0
- package/dist/core/prompt/theme_default.js.map +1 -0
- package/dist/core/prompt/theme_p10k.d.ts +22 -0
- package/dist/core/prompt/theme_p10k.js +164 -0
- package/dist/core/prompt/theme_p10k.js.map +1 -0
- package/dist/core/prompt/utils.d.ts +23 -0
- package/dist/core/prompt/utils.js +40 -0
- package/dist/core/prompt/utils.js.map +1 -0
- package/dist/core/question.d.ts +34 -0
- package/dist/core/question.js +76 -0
- package/dist/core/question.js.map +1 -0
- package/dist/core/repl.d.ts +31 -0
- package/dist/core/repl.js +146 -0
- package/dist/core/repl.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/bootsequence.d.ts +62 -0
- package/dist/lib/bootsequence.js +222 -0
- package/dist/lib/bootsequence.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/logo.d.ts +47 -0
- package/dist/lib/logo.js +313 -0
- package/dist/lib/logo.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 +68 -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 +198 -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 +65 -0
|
@@ -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,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AC,WAAW,CAAC,CAAC;YACjE,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAErC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAO,CAAC,IAAI,EAAE,CAAC;gBACf,SAAS;YACX,CAAC;YAED,MAAM,QAAQ,GAAwB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;YACrF,UAAU,IAAI,UAAU,CAAC,SAAS,CAAC;YACnC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEf,eAAe,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin edit command.
|
|
3
|
+
* Fetches a ChRIS file, opens it in $EDITOR, then deletes and re-uploads on save.
|
|
4
|
+
*/
|
|
5
|
+
import { spawnSync } from 'child_process';
|
|
6
|
+
import { writeFileSync, readFileSync, unlinkSync, existsSync } from 'fs';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import { join, extname, posix } from 'path';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import { path_resolve, error_stripDebugPrefix } from '../utils.js';
|
|
11
|
+
import { files_cat } from '@fnndsc/chili/commands/fs/cat.js';
|
|
12
|
+
import { file_replaceContent } from '@fnndsc/chili/commands/fs/edit.js';
|
|
13
|
+
import { errorStack, listCache_get } from '@fnndsc/cumin';
|
|
14
|
+
const BINARY_EXTENSIONS = new Set([
|
|
15
|
+
'.dcm', '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp', '.ico',
|
|
16
|
+
'.pdf', '.zip', '.tar', '.gz', '.bz2', '.xz', '.7z',
|
|
17
|
+
'.exe', '.dll', '.so', '.bin', '.mp3', '.mp4', '.avi', '.wav',
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* Opens a ChRIS file in $EDITOR. On save, replaces the original via
|
|
21
|
+
* delete + re-upload. No-ops if content is unchanged.
|
|
22
|
+
*
|
|
23
|
+
* @param args - [filePath, ...]
|
|
24
|
+
*/
|
|
25
|
+
export async function builtin_edit(args) {
|
|
26
|
+
if (args.length === 0) {
|
|
27
|
+
console.error(chalk.red('Usage: edit <file>'));
|
|
28
|
+
process.exitCode = 1;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const target = await path_resolve(args[0]);
|
|
32
|
+
const ext = extname(target).toLowerCase();
|
|
33
|
+
if (BINARY_EXTENSIONS.has(ext)) {
|
|
34
|
+
console.error(chalk.red(`edit: ${args[0]}: binary file (${ext}), cannot edit as text`));
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const catResult = await files_cat(target);
|
|
39
|
+
if (!catResult.ok) {
|
|
40
|
+
const err = errorStack.stack_pop();
|
|
41
|
+
console.error(chalk.red(`edit: ${err ? error_stripDebugPrefix(err.message) : 'Failed to read file'}`));
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const originalContent = catResult.value;
|
|
46
|
+
const tmpPath = join(tmpdir(), `chell-edit-${Date.now()}${ext || '.txt'}`);
|
|
47
|
+
let keepTmp = false;
|
|
48
|
+
try {
|
|
49
|
+
writeFileSync(tmpPath, originalContent, 'utf8');
|
|
50
|
+
const editor = process.env.EDITOR || process.env.VISUAL || 'vi';
|
|
51
|
+
const spawn = spawnSync(editor, [tmpPath], { stdio: 'inherit' });
|
|
52
|
+
if (spawn.error) {
|
|
53
|
+
console.error(chalk.red(`edit: Failed to launch '${editor}': ${spawn.error.message}`));
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const editedContent = readFileSync(tmpPath, 'utf8');
|
|
58
|
+
if (editedContent === originalContent) {
|
|
59
|
+
console.log(chalk.gray('(no changes)'));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const result = await file_replaceContent(target, tmpPath);
|
|
63
|
+
listCache_get().cache_invalidate(posix.dirname(target));
|
|
64
|
+
if (result.success) {
|
|
65
|
+
console.log(chalk.green(`Saved: ${args[0]}`));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const apiErr = errorStack.stack_pop();
|
|
69
|
+
console.error(chalk.red(`edit: Save failed — ${result.error}`));
|
|
70
|
+
if (apiErr)
|
|
71
|
+
console.error(chalk.red(` API error: ${error_stripDebugPrefix(apiErr.message)}`));
|
|
72
|
+
console.error(chalk.yellow(`Your edits are preserved at: ${tmpPath}`));
|
|
73
|
+
keepTmp = true;
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
if (!keepTmp && existsSync(tmpPath)) {
|
|
79
|
+
try {
|
|
80
|
+
unlinkSync(tmpPath);
|
|
81
|
+
}
|
|
82
|
+
catch { /* ignore */ }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/builtins/fs/edit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,IAA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AC;gBAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists the contents of the current or specified directory/files in the ChRIS filesystem context.
|
|
3
|
+
* Supports a virtual `/bin` directory for plugins and multiple paths (e.g., from wildcard expansion).
|
|
4
|
+
*
|
|
5
|
+
* @param args - An array containing target paths (optional).
|
|
6
|
+
* @returns A Promise that resolves when the directory contents are listed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function builtin_ls(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin ls command.
|
|
3
|
+
* Lists directory contents.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { commandArgs_process, path_resolve } from '../utils.js';
|
|
7
|
+
import { listCache_get } from '@fnndsc/cumin';
|
|
8
|
+
import { session } from '../../session/index.js';
|
|
9
|
+
import { vfs } from '../../lib/vfs/vfs.js';
|
|
10
|
+
/**
|
|
11
|
+
* Lists the contents of the current or specified directory/files in the ChRIS filesystem context.
|
|
12
|
+
* Supports a virtual `/bin` directory for plugins and multiple paths (e.g., from wildcard expansion).
|
|
13
|
+
*
|
|
14
|
+
* @param args - An array containing target paths (optional).
|
|
15
|
+
* @returns A Promise that resolves when the directory contents are listed.
|
|
16
|
+
*/
|
|
17
|
+
export async function builtin_ls(args) {
|
|
18
|
+
const parsed = commandArgs_process(args);
|
|
19
|
+
const pathArgsRaw = parsed._;
|
|
20
|
+
let sortBy = 'name';
|
|
21
|
+
if (parsed['sort']) {
|
|
22
|
+
const sortValue = String(parsed['sort']);
|
|
23
|
+
if (['name', 'size', 'date', 'owner'].includes(sortValue)) {
|
|
24
|
+
sortBy = sortValue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let pathArgs = pathArgsRaw;
|
|
28
|
+
const shouldRefresh = !!parsed['refresh'] || !!parsed['f'];
|
|
29
|
+
const options = {
|
|
30
|
+
long: !!parsed['l'],
|
|
31
|
+
human: !!parsed['h'],
|
|
32
|
+
oneColumn: !!parsed['1'],
|
|
33
|
+
sort: sortBy,
|
|
34
|
+
reverse: !!parsed['reverse'] || !!parsed['r'],
|
|
35
|
+
directory: !!parsed['d']
|
|
36
|
+
};
|
|
37
|
+
if (shouldRefresh) {
|
|
38
|
+
const listCache = listCache_get();
|
|
39
|
+
if (pathArgs.length === 0) {
|
|
40
|
+
const cwd = await session.getCWD();
|
|
41
|
+
console.log(chalk.gray(`[Cache] Invalidating: ${cwd}`));
|
|
42
|
+
listCache.cache_invalidate(cwd);
|
|
43
|
+
listCache.cache_invalidate();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
for (const pathArg of pathArgs) {
|
|
47
|
+
const resolvedPath = await path_resolve(pathArg);
|
|
48
|
+
console.log(chalk.gray(`[Cache] Invalidating: ${resolvedPath}`));
|
|
49
|
+
listCache.cache_invalidate(resolvedPath);
|
|
50
|
+
}
|
|
51
|
+
listCache.cache_invalidate();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (pathArgs.length === 0) {
|
|
55
|
+
await vfs.list(undefined, options);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (pathArgs.length === 1) {
|
|
59
|
+
const target = await path_resolve(pathArgs[0]);
|
|
60
|
+
await vfs.list(target, options);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const pathArg of pathArgs) {
|
|
64
|
+
const target = await path_resolve(pathArg);
|
|
65
|
+
await vfs.list(target, options);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=ls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/builtins/fs/ls.ts"],"names":[],"mappings":"AA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OAAO,CAAC,CAAC;QACnD,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin mkdir command.
|
|
3
|
+
* Creates directories.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { path_resolve } from '../utils.js';
|
|
7
|
+
import { files_mkdir as chefs_mkdir_cmd } from '@fnndsc/chili/commands/fs/mkdir.js';
|
|
8
|
+
import { mkdir_render } from '@fnndsc/chili/views/fs.js';
|
|
9
|
+
import { listCache_get } from '@fnndsc/cumin';
|
|
10
|
+
/**
|
|
11
|
+
* Creates directories.
|
|
12
|
+
*
|
|
13
|
+
* @param args - Command line arguments (directory paths).
|
|
14
|
+
*/
|
|
15
|
+
export async function builtin_mkdir(args) {
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
console.error(chalk.red('Usage: mkdir <directory> [directory...]'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (const pathArg of args) {
|
|
21
|
+
try {
|
|
22
|
+
const targetPath = await path_resolve(pathArg);
|
|
23
|
+
const success = await chefs_mkdir_cmd(targetPath);
|
|
24
|
+
console.log(mkdir_render(targetPath, success));
|
|
25
|
+
// Invalidate cache for parent directory
|
|
26
|
+
if (success) {
|
|
27
|
+
const parentDir = targetPath.substring(0, targetPath.lastIndexOf('/')) || '/';
|
|
28
|
+
const listCache = listCache_get();
|
|
29
|
+
listCache.cache_invalidate(parentDir);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
34
|
+
console.error(chalk.red(`mkdir: ${pathArg}: ${msg}`));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=mkdir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,OAAO,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Builtin mv command.
|
|
3
|
+
* Moves or renames files/directories.
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { commandArgs_process, path_resolve } from '../utils.js';
|
|
8
|
+
import { files_mv as chefs_mv_cmd } from '@fnndsc/chili/commands/fs/mv.js';
|
|
9
|
+
import { mv_render } from '@fnndsc/chili/views/fs.js';
|
|
10
|
+
import { listCache_get } from '@fnndsc/cumin';
|
|
11
|
+
/**
|
|
12
|
+
* Moves or renames a file or directory.
|
|
13
|
+
* Supports multiple sources when destination is a directory.
|
|
14
|
+
*
|
|
15
|
+
* @param args - [src1, src2, ..., dest] or [src, dest]
|
|
16
|
+
*/
|
|
17
|
+
export async function builtin_mv(args) {
|
|
18
|
+
const parsed = commandArgs_process(args);
|
|
19
|
+
const pathArgs = parsed._;
|
|
20
|
+
if (pathArgs.length < 2) {
|
|
21
|
+
console.log(chalk.red('Usage: mv <source...> <dest>'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// Last arg is destination, all others are sources
|
|
25
|
+
const dest = pathArgs[pathArgs.length - 1];
|
|
26
|
+
const sources = pathArgs.slice(0, -1);
|
|
27
|
+
const destPath = await path_resolve(dest);
|
|
28
|
+
const listCache = listCache_get();
|
|
29
|
+
let successCount = 0;
|
|
30
|
+
let failCount = 0;
|
|
31
|
+
for (const src of sources) {
|
|
32
|
+
try {
|
|
33
|
+
const srcPath = await path_resolve(src);
|
|
34
|
+
// For multiple sources, show which file we're moving
|
|
35
|
+
if (sources.length > 1) {
|
|
36
|
+
console.log(chalk.gray(`Moving ${srcPath}...`));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(`Moving ${srcPath} to ${destPath}...`);
|
|
40
|
+
}
|
|
41
|
+
const success = await chefs_mv_cmd(srcPath, destPath);
|
|
42
|
+
if (sources.length === 1) {
|
|
43
|
+
console.log(mv_render(srcPath, destPath, success));
|
|
44
|
+
}
|
|
45
|
+
if (success) {
|
|
46
|
+
successCount++;
|
|
47
|
+
// Invalidate source directory
|
|
48
|
+
const srcDir = path.posix.dirname(srcPath);
|
|
49
|
+
listCache.cache_invalidate(srcDir);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
failCount++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
57
|
+
console.error(chalk.red(`mv: ${src}: ${msg}`));
|
|
58
|
+
failCount++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Invalidate destination directory (always, since files moved into it)
|
|
62
|
+
listCache.cache_invalidate(destPath);
|
|
63
|
+
const destParent = path.posix.dirname(destPath);
|
|
64
|
+
listCache.cache_invalidate(destParent);
|
|
65
|
+
// Summary for multiple files
|
|
66
|
+
if (sources.length > 1) {
|
|
67
|
+
if (failCount === 0) {
|
|
68
|
+
console.log(chalk.green(`✓ Moved ${successCount} file(s) to ${destPath}`));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
console.log(chalk.yellow(`⚠ Moved ${successCount} file(s), ${failCount} failed`));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=mv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mv.js","sourceRoot":"","sources":["../../../src/builtins/fs/mv.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EA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AK,CAAC,WAAW,YAAY,eAAe,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC7E,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,YAAY,aAAa,SAAS,SAAS,CAAC,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Pure argument parsing for the `pull` builtin.
|
|
3
|
+
*
|
|
4
|
+
* Dependency-free so it is trivially unit-testable.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Parsed `pull` arguments.
|
|
10
|
+
*/
|
|
11
|
+
export interface PullArgs {
|
|
12
|
+
nowait: boolean;
|
|
13
|
+
retryMax: number;
|
|
14
|
+
paths: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parses `pull` arguments: the `--nowait` flag, `--retry N`, and path operands.
|
|
18
|
+
*
|
|
19
|
+
* @param args - Raw command arguments.
|
|
20
|
+
* @returns The parsed flags and paths.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pullArgs_parse(args: string[]): PullArgs;
|