@fnndsc/chili 3.2.5

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.
Files changed (219) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +113 -0
  3. package/dist/chefs/chefs.d.ts +15 -0
  4. package/dist/chefs/chefs.js +195 -0
  5. package/dist/commands/compute/fields.d.ts +6 -0
  6. package/dist/commands/compute/fields.js +13 -0
  7. package/dist/commands/compute/list.d.ts +19 -0
  8. package/dist/commands/compute/list.js +20 -0
  9. package/dist/commands/connect/login.d.ts +16 -0
  10. package/dist/commands/connect/login.js +18 -0
  11. package/dist/commands/connect/logout.d.ts +6 -0
  12. package/dist/commands/connect/logout.js +16 -0
  13. package/dist/commands/feed/comments.d.ts +41 -0
  14. package/dist/commands/feed/comments.js +45 -0
  15. package/dist/commands/feed/create.d.ts +13 -0
  16. package/dist/commands/feed/create.js +40 -0
  17. package/dist/commands/feed/note.d.ts +21 -0
  18. package/dist/commands/feed/note.js +24 -0
  19. package/dist/commands/feeds/delete.d.ts +14 -0
  20. package/dist/commands/feeds/delete.js +34 -0
  21. package/dist/commands/feeds/fields.d.ts +6 -0
  22. package/dist/commands/feeds/fields.js +17 -0
  23. package/dist/commands/feeds/list.d.ts +17 -0
  24. package/dist/commands/feeds/list.js +38 -0
  25. package/dist/commands/feeds/share.d.ts +17 -0
  26. package/dist/commands/feeds/share.js +19 -0
  27. package/dist/commands/file/view.d.ts +8 -0
  28. package/dist/commands/file/view.js +25 -0
  29. package/dist/commands/files/delete.d.ts +16 -0
  30. package/dist/commands/files/delete.js +36 -0
  31. package/dist/commands/files/fields.d.ts +7 -0
  32. package/dist/commands/files/fields.js +18 -0
  33. package/dist/commands/files/list.d.ts +11 -0
  34. package/dist/commands/files/list.js +23 -0
  35. package/dist/commands/fs/cat.d.ts +15 -0
  36. package/dist/commands/fs/cat.js +26 -0
  37. package/dist/commands/fs/cp.d.ts +17 -0
  38. package/dist/commands/fs/cp.js +26 -0
  39. package/dist/commands/fs/create.d.ts +15 -0
  40. package/dist/commands/fs/create.js +83 -0
  41. package/dist/commands/fs/download.d.ts +25 -0
  42. package/dist/commands/fs/download.js +235 -0
  43. package/dist/commands/fs/edit.d.ts +16 -0
  44. package/dist/commands/fs/edit.js +25 -0
  45. package/dist/commands/fs/ls.d.ts +18 -0
  46. package/dist/commands/fs/ls.js +142 -0
  47. package/dist/commands/fs/mkdir.d.ts +8 -0
  48. package/dist/commands/fs/mkdir.js +21 -0
  49. package/dist/commands/fs/mv.d.ts +13 -0
  50. package/dist/commands/fs/mv.js +73 -0
  51. package/dist/commands/fs/rm.d.ts +24 -0
  52. package/dist/commands/fs/rm.js +108 -0
  53. package/dist/commands/fs/touch.d.ts +16 -0
  54. package/dist/commands/fs/touch.js +62 -0
  55. package/dist/commands/fs/upload.d.ts +55 -0
  56. package/dist/commands/fs/upload.js +221 -0
  57. package/dist/commands/groups/fields.d.ts +6 -0
  58. package/dist/commands/groups/fields.js +13 -0
  59. package/dist/commands/groups/list.d.ts +16 -0
  60. package/dist/commands/groups/list.js +26 -0
  61. package/dist/commands/man/doc.d.ts +16 -0
  62. package/dist/commands/man/doc.js +32 -0
  63. package/dist/commands/man/topics.d.ts +6 -0
  64. package/dist/commands/man/topics.js +27 -0
  65. package/dist/commands/pipeline/fields.d.ts +6 -0
  66. package/dist/commands/pipeline/fields.js +13 -0
  67. package/dist/commands/pipeline/run.d.ts +18 -0
  68. package/dist/commands/pipeline/run.js +33 -0
  69. package/dist/commands/plugin/readme.d.ts +14 -0
  70. package/dist/commands/plugin/readme.js +49 -0
  71. package/dist/commands/plugin/run.d.ts +10 -0
  72. package/dist/commands/plugin/run.js +29 -0
  73. package/dist/commands/plugin/search.d.ts +7 -0
  74. package/dist/commands/plugin/search.js +18 -0
  75. package/dist/commands/plugininstances/fields.d.ts +6 -0
  76. package/dist/commands/plugininstances/fields.js +13 -0
  77. package/dist/commands/plugininstances/list.d.ts +16 -0
  78. package/dist/commands/plugininstances/list.js +26 -0
  79. package/dist/commands/pluginmetas/fields.d.ts +6 -0
  80. package/dist/commands/pluginmetas/fields.js +13 -0
  81. package/dist/commands/pluginmetas/list.d.ts +16 -0
  82. package/dist/commands/pluginmetas/list.js +26 -0
  83. package/dist/commands/plugins/add.d.ts +34 -0
  84. package/dist/commands/plugins/add.js +374 -0
  85. package/dist/commands/plugins/delete.d.ts +14 -0
  86. package/dist/commands/plugins/delete.js +34 -0
  87. package/dist/commands/plugins/fields.d.ts +6 -0
  88. package/dist/commands/plugins/fields.js +17 -0
  89. package/dist/commands/plugins/list.d.ts +17 -0
  90. package/dist/commands/plugins/list.js +40 -0
  91. package/dist/commands/plugins/overview.d.ts +6 -0
  92. package/dist/commands/plugins/overview.js +17 -0
  93. package/dist/commands/store/list.d.ts +23 -0
  94. package/dist/commands/store/list.js +48 -0
  95. package/dist/commands/tags/fields.d.ts +6 -0
  96. package/dist/commands/tags/fields.js +13 -0
  97. package/dist/commands/tags/list.d.ts +16 -0
  98. package/dist/commands/tags/list.js +26 -0
  99. package/dist/commands/workflows/fields.d.ts +6 -0
  100. package/dist/commands/workflows/fields.js +13 -0
  101. package/dist/commands/workflows/list.d.ts +16 -0
  102. package/dist/commands/workflows/list.js +26 -0
  103. package/dist/config/colorConfig.d.ts +56 -0
  104. package/dist/config/colorConfig.js +161 -0
  105. package/dist/connect/connectHandler.d.ts +15 -0
  106. package/dist/connect/connectHandler.js +48 -0
  107. package/dist/context/contextCommand.d.ts +13 -0
  108. package/dist/context/contextCommand.js +193 -0
  109. package/dist/controllers/baseController.d.ts +43 -0
  110. package/dist/controllers/baseController.js +67 -0
  111. package/dist/controllers/feedController.d.ts +35 -0
  112. package/dist/controllers/feedController.js +53 -0
  113. package/dist/controllers/fileController.d.ts +56 -0
  114. package/dist/controllers/fileController.js +93 -0
  115. package/dist/controllers/pluginContextController.d.ts +24 -0
  116. package/dist/controllers/pluginContextController.js +49 -0
  117. package/dist/controllers/pluginController.d.ts +70 -0
  118. package/dist/controllers/pluginController.js +98 -0
  119. package/dist/controllers/pluginMetaController.d.ts +41 -0
  120. package/dist/controllers/pluginMetaController.js +52 -0
  121. package/dist/feeds/feedHandler.d.ts +64 -0
  122. package/dist/feeds/feedHandler.js +203 -0
  123. package/dist/filesystem/fileGroupHandler.d.ts +92 -0
  124. package/dist/filesystem/fileGroupHandler.js +318 -0
  125. package/dist/filesystem/filesystemHandler.d.ts +12 -0
  126. package/dist/filesystem/filesystemHandler.js +135 -0
  127. package/dist/filesystem/inodeCommand.d.ts +12 -0
  128. package/dist/filesystem/inodeCommand.js +37 -0
  129. package/dist/handlers/baseGroupHandler.d.ts +103 -0
  130. package/dist/handlers/baseGroupHandler.js +342 -0
  131. package/dist/index.d.ts +7 -0
  132. package/dist/index.js +239 -0
  133. package/dist/lfs/lfs.d.ts +25 -0
  134. package/dist/lfs/lfs.js +74 -0
  135. package/dist/man/man.d.ts +15 -0
  136. package/dist/man/man.js +31 -0
  137. package/dist/man/renderer.d.ts +26 -0
  138. package/dist/man/renderer.js +187 -0
  139. package/dist/models/feed.d.ts +18 -0
  140. package/dist/models/feed.js +8 -0
  141. package/dist/models/listing.d.ts +33 -0
  142. package/dist/models/listing.js +9 -0
  143. package/dist/models/plugin.d.ts +27 -0
  144. package/dist/models/plugin.js +1 -0
  145. package/dist/models/resource.d.ts +39 -0
  146. package/dist/models/resource.js +9 -0
  147. package/dist/pacs/pacsQueryHandler.d.ts +55 -0
  148. package/dist/pacs/pacsQueryHandler.js +196 -0
  149. package/dist/pacs/pacsQueryPayload.d.ts +19 -0
  150. package/dist/pacs/pacsQueryPayload.js +44 -0
  151. package/dist/pacs/pacsResultRender.d.ts +20 -0
  152. package/dist/pacs/pacsResultRender.js +141 -0
  153. package/dist/pacs/pacsRetrieveHandler.d.ts +87 -0
  154. package/dist/pacs/pacsRetrieveHandler.js +272 -0
  155. package/dist/pacs/pacsServerHandler.d.ts +15 -0
  156. package/dist/pacs/pacsServerHandler.js +32 -0
  157. package/dist/path/pathCommand.d.ts +64 -0
  158. package/dist/path/pathCommand.js +805 -0
  159. package/dist/path/pathMapper.d.ts +189 -0
  160. package/dist/path/pathMapper.js +382 -0
  161. package/dist/plugins/pluginGroupHandler.d.ts +42 -0
  162. package/dist/plugins/pluginGroupHandler.js +90 -0
  163. package/dist/plugins/pluginHandler.d.ts +87 -0
  164. package/dist/plugins/pluginHandler.js +303 -0
  165. package/dist/plugins/pluginMetaHandler.d.ts +21 -0
  166. package/dist/plugins/pluginMetaHandler.js +27 -0
  167. package/dist/screen/screen.d.ts +214 -0
  168. package/dist/screen/screen.js +478 -0
  169. package/dist/utils/admin_prompt.d.ts +42 -0
  170. package/dist/utils/admin_prompt.js +105 -0
  171. package/dist/utils/cli.d.ts +67 -0
  172. package/dist/utils/cli.js +112 -0
  173. package/dist/utils/docker.d.ts +74 -0
  174. package/dist/utils/docker.js +155 -0
  175. package/dist/utils/input_format.d.ts +77 -0
  176. package/dist/utils/input_format.js +135 -0
  177. package/dist/utils/sort.d.ts +29 -0
  178. package/dist/utils/sort.js +63 -0
  179. package/dist/utils/ui.d.ts +7 -0
  180. package/dist/utils/ui.js +26 -0
  181. package/dist/utils.d.ts +15 -0
  182. package/dist/utils.js +14 -0
  183. package/dist/views/compute.d.ts +17 -0
  184. package/dist/views/compute.js +40 -0
  185. package/dist/views/connect.d.ts +13 -0
  186. package/dist/views/connect.js +35 -0
  187. package/dist/views/feed.d.ts +44 -0
  188. package/dist/views/feed.js +110 -0
  189. package/dist/views/file.d.ts +25 -0
  190. package/dist/views/file.js +71 -0
  191. package/dist/views/fs.d.ts +51 -0
  192. package/dist/views/fs.js +105 -0
  193. package/dist/views/ls.d.ts +37 -0
  194. package/dist/views/ls.js +190 -0
  195. package/dist/views/plugin.d.ts +28 -0
  196. package/dist/views/plugin.js +71 -0
  197. package/dist/views/pluginParameters.d.ts +17 -0
  198. package/dist/views/pluginParameters.js +79 -0
  199. package/docs/00_intro.adoc +25 -0
  200. package/docs/01_setup.adoc +63 -0
  201. package/docs/02_context.adoc +128 -0
  202. package/docs/03_searchable.adoc +134 -0
  203. package/docs/10_everyday_examples.adoc +9 -0
  204. package/docs/11_upload_data.adoc +146 -0
  205. package/docs/12_create_a_feed.adoc +9 -0
  206. package/docs/13_run_a_plugin.adoc +271 -0
  207. package/docs/20_plugins.adoc +16 -0
  208. package/docs/21_pluginReadme.adoc +123 -0
  209. package/docs/30_filesystem.adoc +93 -0
  210. package/docs/31_fileops.adoc +51 -0
  211. package/docs/32_file_content.adoc +471 -0
  212. package/docs/_architecture.adoc +48 -0
  213. package/docs/_deepContext.adoc +84 -0
  214. package/docs/_roadmap.adoc +42 -0
  215. package/docs/_searchable.adoc +187 -0
  216. package/docs/_state.adoc +68 -0
  217. package/docs/pacs.adoc +101 -0
  218. package/docs/pathMapper.md +246 -0
  219. package/package.json +92 -0
package/dist/index.js ADDED
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @file Command-line entry point for the chili (ChILI) CLI.
4
+ *
5
+ * @module
6
+ */
7
+ /**
8
+ * Suppress DEP0169 warning from axios/proxy-from-env dependency.
9
+ *
10
+ * This warning originates from the `proxy-from-env` package (version 1.1.0)
11
+ * used by axios for proxy configuration. The package uses the legacy `url.parse()`
12
+ * API which is deprecated in favor of the WHATWG URL API.
13
+ *
14
+ * Why we suppress it:
15
+ * - It's a transitive dependency (axios → proxy-from-env) we don't control
16
+ * - proxy-from-env 1.1.0 is the latest version and hasn't been updated
17
+ * - According to the warning: "CVEs are not issued for url.parse() vulnerabilities"
18
+ * - The warning doesn't affect functionality, only console output
19
+ * - This is a well-known issue in the Node.js ecosystem
20
+ *
21
+ * This can be removed once:
22
+ * - proxy-from-env migrates to WHATWG URL API, OR
23
+ * - axios replaces proxy-from-env with an alternative
24
+ *
25
+ * Tracking: https://github.com/Rob--W/proxy-from-env/issues/51
26
+ */
27
+ const originalEmitWarning = process.emitWarning;
28
+ process.emitWarning = function (warning, ...args) {
29
+ // Suppress only the specific DEP0169 warning
30
+ if (typeof warning === 'string' &&
31
+ (warning.includes('DEP0169') || warning.includes('url.parse()'))) {
32
+ return;
33
+ }
34
+ // Allow all other warnings through
35
+ return originalEmitWarning.call(process, warning, ...args);
36
+ };
37
+ import { Command } from "commander";
38
+ import figlet from "figlet";
39
+ import omelette from "omelette";
40
+ import { connectCommand_setup } from "./connect/connectHandler.js";
41
+ import { FeedGroupHandler, FeedMemberHandler } from "./feeds/feedHandler.js";
42
+ import { PluginGroupHandler, PluginMemberHandler, } from "./plugins/pluginHandler.js";
43
+ import { PluginMetaGroupHandler } from "./plugins/pluginMetaHandler.js";
44
+ import { PluginContextGroupHandler } from "./plugins/pluginGroupHandler.js";
45
+ import { inodeCommand_setup } from "./filesystem/inodeCommand.js";
46
+ import { contextCommand_setup } from "./context/contextCommand.js";
47
+ import { pathCommand_setup } from "./path/pathCommand.js";
48
+ import { fileBrowserCommand_setup } from "./filesystem/filesystemHandler.js";
49
+ import { manCommand_setup } from "./man/man.js";
50
+ import { chefsCommand_setup } from "./chefs/chefs.js";
51
+ import { PACSServerGroupHandler } from "./pacs/pacsServerHandler.js";
52
+ import { PACSQueryGroupHandler } from "./pacs/pacsQueryHandler.js";
53
+ import { PACSRetrieveGroupHandler } from "./pacs/pacsRetrieveHandler.js";
54
+ import { chrisConnection_init, NodeStorageProvider, errorStack_getAllOfType } from "@fnndsc/cumin";
55
+ import { FileGroupHandler } from "./filesystem/fileGroupHandler.js";
56
+ const program = new Command();
57
+ program.version("1.0.1").description("A CLI for ChRIS");
58
+ /**
59
+ * Sets up command completion for the ChILI CLI using omelette.
60
+ * This provides auto-completion suggestions in the shell.
61
+ */
62
+ function commandCompletion_setup() {
63
+ const completion = omelette(`chili|chili`);
64
+ completion.tree({
65
+ connect: ["--user", "--password"],
66
+ man: {
67
+ doc: [], // We'll populate this later with actual topics
68
+ },
69
+ chefs: ["ls", "mkdir", "touch"],
70
+ plugins: {
71
+ list: ["--page", "--fields", "--search"],
72
+ info: ["<pluginId>"],
73
+ fieldslist: [],
74
+ delete: ["<IDs>", "--search", "--force"],
75
+ },
76
+ feeds: {
77
+ list: ["--page", "--fields", "--search"],
78
+ new: ["--name", "--path"],
79
+ fieldslist: [],
80
+ delete: ["<IDs>", "--search", "--force"],
81
+ },
82
+ inode: {
83
+ "<path>": {
84
+ files: {
85
+ list: ["--page", "--fields", "--search"],
86
+ fieldslist: [],
87
+ delete: ["<IDs>", "--search", "--force"],
88
+ share: ["--force"],
89
+ },
90
+ file: {
91
+ view: ["--type"],
92
+ },
93
+ },
94
+ },
95
+ });
96
+ completion.on("man.doc", ({ reply }) => {
97
+ console.log("Autocomplete triggered for man doc command");
98
+ // We'll implement actual topic retrieval here later
99
+ reply([]);
100
+ });
101
+ completion.init();
102
+ if (~process.argv.indexOf("--completion")) {
103
+ completion.setupShellInitFile();
104
+ }
105
+ }
106
+ /**
107
+ * Initializes and sets up all command handlers for the ChILI CLI.
108
+ *
109
+ * @param program - The Commander.js program instance.
110
+ */
111
+ async function handlers_initialize() {
112
+ // const client = await chrisConnection.client_get();
113
+ // We don't enforce connection here to allow --help to work.
114
+ // Commands will fail individually if not connected.
115
+ fileBrowserCommand_setup(program);
116
+ contextCommand_setup(program);
117
+ pathCommand_setup(program);
118
+ manCommand_setup(program);
119
+ chefsCommand_setup(program);
120
+ const pacsServerHandler = new PACSServerGroupHandler();
121
+ pacsServerHandler.pacsServerCommand_setup(program);
122
+ const pacsQueryHandler = new PACSQueryGroupHandler();
123
+ pacsQueryHandler.pacsQueryCommand_setup(program);
124
+ const pacsRetrieveHandler = new PACSRetrieveGroupHandler();
125
+ pacsRetrieveHandler.pacsRetrieveCommand_setup(program);
126
+ await inodeCommand_setup(program);
127
+ const pluginGroupHandler = new PluginGroupHandler();
128
+ pluginGroupHandler.pluginGroupCommand_setup(program);
129
+ const pluginMetaGroupHandler = new PluginMetaGroupHandler();
130
+ pluginMetaGroupHandler.pluginMetaGroupCommand_setup(program);
131
+ const feedGroupHandler = new FeedGroupHandler();
132
+ feedGroupHandler.feedGroupCommand_setup(program);
133
+ const feedMemberHandler = new FeedMemberHandler();
134
+ feedMemberHandler.feedCommand_setup(program);
135
+ const pluginMemberHandler = new PluginMemberHandler();
136
+ pluginMemberHandler.pluginCommand_setup(program);
137
+ try {
138
+ const filesGroupHandler = await FileGroupHandler.handler_create("files");
139
+ filesGroupHandler.fileGroupCommand_setup(program);
140
+ const linksGroupHandler = await FileGroupHandler.handler_create("links");
141
+ linksGroupHandler.fileGroupCommand_setup(program);
142
+ const dirsGroupHandler = await FileGroupHandler.handler_create("dirs");
143
+ dirsGroupHandler.fileGroupCommand_setup(program);
144
+ }
145
+ catch (e) {
146
+ const err = e instanceof Error ? e.message : String(e);
147
+ const errors = errorStack_getAllOfType("error");
148
+ const warnings = errorStack_getAllOfType("warning");
149
+ console.log(`Note: File group commands (files, dirs, links) are unavailable. Reason: ${err}`);
150
+ if (errors.length > 0) {
151
+ console.log("Errors:");
152
+ errors.forEach(msg => console.log(` - ${msg}`));
153
+ }
154
+ if (warnings.length > 0) {
155
+ console.log("Warnings:");
156
+ warnings.forEach(msg => console.log(` - ${msg}`));
157
+ }
158
+ }
159
+ try {
160
+ const computesOfPluginHandler = await PluginContextGroupHandler.handler_create("computesofplugin");
161
+ computesOfPluginHandler.pluginContextGroupCommand_setup(program);
162
+ const pluginInstancesHandler = await PluginContextGroupHandler.handler_create("instancesofplugin");
163
+ pluginInstancesHandler.pluginContextGroupCommand_setup(program);
164
+ const pluginParametersHandler = await PluginContextGroupHandler.handler_create("parametersofplugin");
165
+ pluginParametersHandler.pluginContextGroupCommand_setup(program);
166
+ }
167
+ catch (e) {
168
+ const err = e instanceof Error ? e.message : String(e);
169
+ const errors = errorStack_getAllOfType("error");
170
+ const warnings = errorStack_getAllOfType("warning");
171
+ console.log(`Note: Plugin context commands are unavailable. Reason: ${err}`);
172
+ if (errors.length > 0) {
173
+ console.log("Errors:");
174
+ errors.forEach(msg => console.log(` - ${msg}`));
175
+ }
176
+ if (warnings.length > 0) {
177
+ console.log("Warnings:");
178
+ warnings.forEach(msg => console.log(` - ${msg}`));
179
+ }
180
+ }
181
+ commandCompletion_setup();
182
+ }
183
+ /**
184
+ * Parses the command line arguments to extract context information.
185
+ *
186
+ * @param args - The command line arguments array (process.argv).
187
+ * @returns A tuple containing the context string (if found) and the remaining arguments.
188
+ */
189
+ function context_parse(args) {
190
+ // Find the first argument that looks like a context string (contains "=" but doesn't start with "-")
191
+ for (let i = 2; i < args.length; i++) {
192
+ const arg = args[i];
193
+ if (arg.includes("=") && !arg.startsWith("-")) {
194
+ const context = arg;
195
+ // Reconstruct args without the context string
196
+ const newArgs = [...args.slice(0, i), ...args.slice(i + 1)];
197
+ return [context, newArgs];
198
+ }
199
+ }
200
+ return [undefined, args];
201
+ }
202
+ /**
203
+ * Main function to run the ChILI CLI.
204
+ * Handles initialization, context parsing, and command execution.
205
+ */
206
+ async function main() {
207
+ const nodeStorageProvider = new NodeStorageProvider();
208
+ const connection = await chrisConnection_init(nodeStorageProvider);
209
+ const [context, newArgs] = context_parse(process.argv);
210
+ if (context) {
211
+ const contextSetSuccess = await connection.context_set(context);
212
+ if (!contextSetSuccess) {
213
+ console.error("Failed to set context. Exiting.");
214
+ process.exit(1);
215
+ }
216
+ process.argv = newArgs;
217
+ }
218
+ program
219
+ .name("chili")
220
+ .description("ChILI handles Intelligent Line Interactions")
221
+ .option("-v, --verbose", "enable verbose output")
222
+ .option("-c, --config <path>", "path to config file")
223
+ .option("-s, --nosplash", "disable splash screen");
224
+ connectCommand_setup(program);
225
+ await handlers_initialize(); // Call handlers_initialize here
226
+ program.parseOptions(process.argv);
227
+ const options = program.opts();
228
+ if (!options.nosplash) {
229
+ console.log(figlet.textSync("ChILI"));
230
+ console.log("ChILI handles Intelligent Line Interactions");
231
+ }
232
+ program.parse(process.argv);
233
+ }
234
+ main().catch((error) => {
235
+ console.error("An error occurred:", error);
236
+ process.exit(1);
237
+ });
238
+ // Export utilities for use by other packages (e.g., chell)
239
+ export { logical_toPhysical } from './utils/cli.js';
@@ -0,0 +1,25 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Lists the contents of a directory with details.
4
+ *
5
+ * @param filepath - The directory path to list.
6
+ */
7
+ export declare function dirContents_list(filepath: string): Promise<void>;
8
+ /**
9
+ * Creates a directory if it does not exist.
10
+ *
11
+ * @param filepath - The directory path to create.
12
+ */
13
+ export declare function dir_create(filepath: string): void;
14
+ /**
15
+ * Creates an empty file.
16
+ *
17
+ * @param filepath - The file path to create.
18
+ */
19
+ export declare function file_create(filepath: string): void;
20
+ /**
21
+ * Sets up the 'lfs' command group in Commander.
22
+ *
23
+ * @param program - The Commander program instance.
24
+ */
25
+ export declare function lfsCommand_setup(program: Command): void;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @file Local File System (LFS) Operations.
3
+ *
4
+ * This module provides command implementations for interacting with the
5
+ * local filesystem, mirroring standard shell commands like ls, mkdir, touch.
6
+ *
7
+ * @module
8
+ */
9
+ import * as fs from 'fs';
10
+ import * as path from 'path';
11
+ /**
12
+ * Lists the contents of a directory with details.
13
+ *
14
+ * @param filepath - The directory path to list.
15
+ */
16
+ export async function dirContents_list(filepath) {
17
+ try {
18
+ const files = await fs.promises.readdir(filepath);
19
+ const detailedFilesPromises = files.map(async (file) => {
20
+ let fileDetails = await fs.promises.lstat(path.resolve(filepath, file));
21
+ const { size, birthtime } = fileDetails;
22
+ return { filename: file, "size(KB)": size, created_at: birthtime };
23
+ });
24
+ const detailedFiles = await Promise.all(detailedFilesPromises);
25
+ console.table(detailedFiles);
26
+ }
27
+ catch (error) {
28
+ console.error("Error occurred while reading the directory!", error);
29
+ }
30
+ }
31
+ /**
32
+ * Creates a directory if it does not exist.
33
+ *
34
+ * @param filepath - The directory path to create.
35
+ */
36
+ export function dir_create(filepath) {
37
+ if (!fs.existsSync(filepath)) {
38
+ fs.mkdirSync(filepath);
39
+ console.log("The directory has been created successfully");
40
+ }
41
+ }
42
+ /**
43
+ * Creates an empty file.
44
+ *
45
+ * @param filepath - The file path to create.
46
+ */
47
+ export function file_create(filepath) {
48
+ fs.openSync(filepath, "w");
49
+ console.log("An empty file has been created");
50
+ }
51
+ /**
52
+ * Sets up the 'lfs' command group in Commander.
53
+ *
54
+ * @param program - The Commander program instance.
55
+ */
56
+ export function lfsCommand_setup(program) {
57
+ const lfs = program.command('lfs')
58
+ .description('Local filesystem operations');
59
+ lfs.command('ls [directory]')
60
+ .description('List directory contents')
61
+ .action(async (directory = process.cwd()) => {
62
+ await dirContents_list(directory);
63
+ });
64
+ lfs.command('mkdir <directory>')
65
+ .description('Create a directory')
66
+ .action((directory) => {
67
+ dir_create(path.resolve(process.cwd(), directory));
68
+ });
69
+ lfs.command('touch <file>')
70
+ .description('Create a file')
71
+ .action((file) => {
72
+ file_create(path.resolve(process.cwd(), file));
73
+ });
74
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file Implements the setup for manual/documentation CLI commands.
3
+ *
4
+ * This module provides the `manCommand_setup` function which configures
5
+ * the `man` command group in the main CLI program.
6
+ *
7
+ * @module
8
+ */
9
+ import { Command } from "commander";
10
+ /**
11
+ * Sets up the 'man' command for displaying ChILI manual and help pages.
12
+ *
13
+ * @param program - The Commander.js program instance.
14
+ */
15
+ export declare function manCommand_setup(program: Command): void;
@@ -0,0 +1,31 @@
1
+ import { topics_list } from "../commands/man/topics.js";
2
+ import { manPage_display } from "../commands/man/doc.js";
3
+ /**
4
+ * Sets up the 'man' command for displaying ChILI manual and help pages.
5
+ *
6
+ * @param program - The Commander.js program instance.
7
+ */
8
+ export function manCommand_setup(program) {
9
+ const manCommand = program
10
+ .command("man")
11
+ .description("ChILI built in manual and help pages");
12
+ manCommand
13
+ .command("doc <topic>")
14
+ .description("Display the manual document for a ChILI topic")
15
+ .option("-b, --browser", "Open documentation in browser")
16
+ .option("--style <style>", "Styling for headings", "figlet")
17
+ .option("--width <N>", "Number of columns in the text response", parseInt)
18
+ .action(async (topic, options) => {
19
+ options.topic = topic;
20
+ await manPage_display(options);
21
+ });
22
+ manCommand
23
+ .command("topics")
24
+ .description("List the available manual page topics")
25
+ .action(async () => {
26
+ const files = await topics_list();
27
+ console.log("\n\nThe following topics are available:");
28
+ console.log("(read more with 'chili man doc <topic>')\n");
29
+ console.log(files.join("\n"));
30
+ });
31
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file AsciiDoc/man page rendering and browser-open helpers.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Determines the root project directory by looking for `package.json`.
8
+ *
9
+ * @returns The absolute path to the project directory.
10
+ */
11
+ export declare function projectDir_get(): string;
12
+ /**
13
+ * Renders AsciiDoc content to a formatted string for console display.
14
+ *
15
+ * @param content - The AsciiDoc content string.
16
+ * @param style - The rendering style ('figlet' or 'ascii').
17
+ * @param width - Optional width for text wrapping.
18
+ * @returns A Promise resolving to the formatted string.
19
+ */
20
+ export declare function asciidoc_render(content: string, style: "figlet" | "ascii", width?: number): Promise<string>;
21
+ /**
22
+ * Opens a local file in the default web browser.
23
+ *
24
+ * @param filePath - The path to the file to open.
25
+ */
26
+ export declare function browser_open(filePath: string): void;
@@ -0,0 +1,187 @@
1
+ /**
2
+ * @file AsciiDoc/man page rendering and browser-open helpers.
3
+ *
4
+ * @module
5
+ */
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import chalk from "chalk";
9
+ import asciidoctor from "asciidoctor";
10
+ import { exec } from "child_process";
11
+ import os from "os";
12
+ const headingStyles = [
13
+ { regex: /<h1.*?>(.*?)<\/h1>/g, font: "Standard", color: chalk.magenta },
14
+ { regex: /<h2.*?>(.*?)<\/h2>/g, font: "Slant", color: chalk.yellow },
15
+ { regex: /<h3.*?>(.*?)<\/h3>/g, font: "Small", color: chalk.green },
16
+ { regex: /<h4.*?>(.*?)<\/h4>/g, font: "Mini", color: chalk.blue },
17
+ ];
18
+ const asciiHeadingStyles = [
19
+ {
20
+ regex: /<h1.*?>(.*?)<\/h1>/g,
21
+ textTransform: (text) => text.toUpperCase(),
22
+ color: chalk.yellow,
23
+ },
24
+ {
25
+ regex: /<h2.*?>(.*?)<\/h2>/g,
26
+ textTransform: (text) => text.toUpperCase(),
27
+ color: chalk.yellow.italic,
28
+ },
29
+ {
30
+ regex: /<h3.*?>(.*?)<\/h3>/g,
31
+ textTransform: (text) => text,
32
+ color: chalk.cyan,
33
+ },
34
+ {
35
+ regex: /<h4.*?>(.*?)<\/h4>/g,
36
+ textTransform: (text) => text,
37
+ color: chalk.cyan.italic,
38
+ },
39
+ ];
40
+ /**
41
+ * Determines the root project directory by looking for `package.json`.
42
+ *
43
+ * @returns The absolute path to the project directory.
44
+ */
45
+ export function projectDir_get() {
46
+ // Fallback for tests and dev environment
47
+ let directoryToCheck = process.cwd();
48
+ while (directoryToCheck) {
49
+ const packageJsonPath = path.join(directoryToCheck, "package.json");
50
+ if (fs.existsSync(packageJsonPath)) {
51
+ return directoryToCheck;
52
+ }
53
+ const parent = path.dirname(directoryToCheck);
54
+ if (parent === directoryToCheck)
55
+ break; // Root reached
56
+ directoryToCheck = parent;
57
+ }
58
+ return process.cwd();
59
+ }
60
+ /**
61
+ * Converts AsciiDoc content to HTML.
62
+ *
63
+ * @param content - The AsciiDoc content string.
64
+ * @returns The converted HTML string.
65
+ */
66
+ function adoc_htmlConvert(content) {
67
+ const ascii = asciidoctor();
68
+ let result = ascii.convert(content, {
69
+ standalone: false,
70
+ attributes: {
71
+ showtitle: "",
72
+ sectlinks: "",
73
+ sectanchors: "",
74
+ },
75
+ });
76
+ return result;
77
+ }
78
+ /**
79
+ * Wraps text to a specified width.
80
+ *
81
+ * @param text - The text to wrap.
82
+ * @param width - The maximum line width.
83
+ * @returns The wrapped text.
84
+ */
85
+ function text_wrap(text, width) {
86
+ if (!width || width <= 0)
87
+ return text;
88
+ const words = text.split(" ");
89
+ let wrappedText = "";
90
+ let line = "";
91
+ for (const word of words) {
92
+ if ((line + word).length > width) {
93
+ wrappedText += (wrappedText ? "\n" : "") + line.trim();
94
+ line = "";
95
+ }
96
+ line += word + " ";
97
+ }
98
+ wrappedText += (wrappedText ? "\n" : "") + line.trim();
99
+ return wrappedText;
100
+ }
101
+ /**
102
+ * Renders AsciiDoc content to a formatted string for console display.
103
+ *
104
+ * @param content - The AsciiDoc content string.
105
+ * @param style - The rendering style ('figlet' or 'ascii').
106
+ * @param width - Optional width for text wrapping.
107
+ * @returns A Promise resolving to the formatted string.
108
+ */
109
+ export async function asciidoc_render(content, style, width) {
110
+ let result = adoc_htmlConvert(content);
111
+ function ASCII_create(text, style) {
112
+ const transformedText = style.textTransform(text);
113
+ return style.color(transformedText);
114
+ }
115
+ const heading_process = async (text, style, figletStyle, asciiStyle) => {
116
+ if (style === "figlet") {
117
+ // Fallback to simple color as figlet is disabled in this environment
118
+ return figletStyle.color(text);
119
+ }
120
+ else {
121
+ return ASCII_create(text, asciiStyle);
122
+ }
123
+ };
124
+ for (let i = 0; i < headingStyles.length; i++) {
125
+ const figletStyle = headingStyles[i];
126
+ const asciiStyle = asciiHeadingStyles[i];
127
+ const matches = result.match(figletStyle.regex) || [];
128
+ for (const match of matches) {
129
+ const text = match
130
+ .replace(/<\/?h[1-4].*?>/g, "")
131
+ .replace(/<a.*?>(.*?)<\/a>/g, "$1");
132
+ const processed = await heading_process(text, style, figletStyle, asciiStyle);
133
+ result = result.replace(match, `\n${processed}\n`);
134
+ }
135
+ }
136
+ result = result
137
+ .replace(/<code>(.*?)<\/code>/g, (_, p1) => chalk.cyan(p1))
138
+ .replace(/<em>(.*?)<\/em>/g, (_, p1) => chalk.italic(p1))
139
+ .replace(/<\/div.*?>/g, "")
140
+ .replace(/<p>(.*?)<\/p>/g, "$1\n")
141
+ .replace(/&lt;/g, "<")
142
+ .replace(/&gt;/g, ">")
143
+ .replace(/&amp;/g, "&")
144
+ .replace(/<a.*?>(.*?)<\/a>/g, "$1")
145
+ .replace(/<\/?(?!a)[^>]+(>|$)/g, "")
146
+ .replace(/\n{3,}/g, "\n\n") // Replace 3 or more newlines with 2
147
+ .trim();
148
+ // Wrap the result if width is specified
149
+ if (width) {
150
+ result = result
151
+ .split("\n")
152
+ .map((line) => text_wrap(line, width))
153
+ .join("\n");
154
+ }
155
+ return result;
156
+ }
157
+ /**
158
+ * Opens a local file in the default web browser.
159
+ *
160
+ * @param filePath - The path to the file to open.
161
+ */
162
+ export function browser_open(filePath) {
163
+ const ascii = asciidoctor();
164
+ const tempHtmlPath = path.join(os.tmpdir(), path.basename(filePath).replace(".adoc", ".html"));
165
+ try {
166
+ const content = fs.readFileSync(filePath, "utf-8");
167
+ const html = ascii.convert(content, {
168
+ safe: "safe",
169
+ standalone: true,
170
+ attributes: { showtitle: true },
171
+ });
172
+ fs.writeFileSync(tempHtmlPath, html);
173
+ const command = process.platform === "win32"
174
+ ? "start"
175
+ : process.platform === "darwin"
176
+ ? "open"
177
+ : "xdg-open";
178
+ exec(`${command} ${tempHtmlPath}`, (error) => {
179
+ if (error) {
180
+ console.error("Error opening browser:", error);
181
+ }
182
+ });
183
+ }
184
+ catch (error) {
185
+ console.error("Error opening documentation in browser:", error instanceof Error ? error.message : String(error));
186
+ }
187
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file Models for Feed operations.
3
+ *
4
+ * Defines the data structures for ChRIS Feeds.
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * Represents a ChRIS Feed.
10
+ */
11
+ export interface Feed {
12
+ id: number;
13
+ name: string;
14
+ creation_date: string;
15
+ modification_date: string;
16
+ owner_username?: string;
17
+ [key: string]: unknown;
18
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @file Models for Feed operations.
3
+ *
4
+ * Defines the data structures for ChRIS Feeds.
5
+ *
6
+ * @module
7
+ */
8
+ export {};
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file Models for file system listings.
3
+ *
4
+ * Defines the standardized "View Model" for items appearing in `ls` lists,
5
+ * regardless of whether they are native files, directories, or virtual plugins.
6
+ *
7
+ * @module
8
+ */
9
+ import { SimpleRecord } from '@fnndsc/cumin';
10
+ /**
11
+ * Interface representing a rich file system item.
12
+ * Contains all metadata required for various views (Grid, Long, JSON).
13
+ */
14
+ export interface ListingItem extends SimpleRecord {
15
+ /** The display name of the item. */
16
+ name: string;
17
+ /** The type of the item. */
18
+ type: 'dir' | 'file' | 'link' | 'plugin' | 'pipeline' | 'vfs' | 'job';
19
+ /** Size in bytes. */
20
+ size: number;
21
+ /** Username of the owner. */
22
+ owner: string;
23
+ /** Creation date (ISO string). */
24
+ date: string;
25
+ /** Target path (for links). */
26
+ target?: string;
27
+ /** Version string (for plugins). */
28
+ version?: string;
29
+ /** Title or description (for feeds, plugin instances). */
30
+ title?: string;
31
+ /** Execution status (for job type items). */
32
+ status?: string;
33
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @file Models for file system listings.
3
+ *
4
+ * Defines the standardized "View Model" for items appearing in `ls` lists,
5
+ * regardless of whether they are native files, directories, or virtual plugins.
6
+ *
7
+ * @module
8
+ */
9
+ export {};