@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
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @file Handler for the plugin context command group.
3
+ *
4
+ * @module
5
+ */
6
+ import { BaseGroupHandler } from "../handlers/baseGroupHandler.js";
7
+ import { options_toParams } from "../utils/cli.js";
8
+ import { PluginContextController } from "../controllers/pluginContextController.js";
9
+ import { pluginParameters_renderMan } from "../views/pluginParameters.js";
10
+ class InitializationError extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "InitializationError";
14
+ }
15
+ }
16
+ /**
17
+ * Handles commands related to groups of plugin contexts (computes, instances, parameters).
18
+ */
19
+ export class PluginContextGroupHandler {
20
+ constructor(controller, assetName) {
21
+ this.baseGroupHandler = null;
22
+ this.controller = controller;
23
+ this.assetName = assetName;
24
+ // Cast ChRISEmbeddedResourceGroup to ChRISEmbeddedResourceGroup<unknown> safely.
25
+ this.baseGroupHandler = new BaseGroupHandler(this.assetName, this.controller.chrisObject);
26
+ }
27
+ /**
28
+ * Factory method to create a new PluginContextGroupHandler instance.
29
+ *
30
+ * @param assetName - The type of plugin context to handle ('computesofplugin', 'instancesofplugin', 'parametersofplugin').
31
+ * @param id - Optional plugin ID. Defaults to current ChRIS plugin context.
32
+ * @returns A Promise resolving to a new PluginContextGroupHandler instance.
33
+ * @throws InitializationError if an unsupported asset type is provided.
34
+ */
35
+ static async handler_create(assetName, id) {
36
+ try {
37
+ const controller = await PluginContextController.controller_create(assetName, id);
38
+ return new PluginContextGroupHandler(controller, assetName);
39
+ }
40
+ catch (error) {
41
+ throw new InitializationError(`Failed to initialize PluginContextGroupHandler: ${error}`);
42
+ }
43
+ }
44
+ /**
45
+ * Lists plugin parameters in a "man page" style format.
46
+ * This is a specialized view for parameters that differs from the standard table view.
47
+ *
48
+ * @param options - CLI options for filtering.
49
+ */
50
+ async parameters_listMan(options) {
51
+ try {
52
+ // We access the asset directly from the controller
53
+ const asset = this.controller.chrisObject.asset;
54
+ if (!asset || typeof asset.resources_listAndFilterByOptions !== 'function') {
55
+ console.error("Underlying resource does not support listing.");
56
+ return;
57
+ }
58
+ const params = options_toParams(options);
59
+ const results = await asset.resources_listAndFilterByOptions(params);
60
+ if (results) {
61
+ pluginParameters_renderMan(results);
62
+ }
63
+ else {
64
+ console.log("No parameters found.");
65
+ }
66
+ }
67
+ catch (error) {
68
+ console.error(`Error listing parameters: ${error}`);
69
+ }
70
+ }
71
+ /**
72
+ * Lists available fields for the current plugin context resource.
73
+ */
74
+ async parameters_fieldsList() {
75
+ if (this.baseGroupHandler) {
76
+ await this.baseGroupHandler.resourceFields_list();
77
+ }
78
+ }
79
+ /**
80
+ * Sets up the Commander.js commands for plugin context group operations.
81
+ *
82
+ * @param program - The Commander.js program instance.
83
+ */
84
+ pluginContextGroupCommand_setup(program) {
85
+ if (this.baseGroupHandler) {
86
+ this.baseGroupHandler.command_setup(program);
87
+ }
88
+ const fileGroupCommand = program.commands.find((cmd) => cmd.name() === this.assetName);
89
+ }
90
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @file Manages command groups and member operations for ChRIS plugins.
3
+ *
4
+ * This module defines the `PluginGroupHandler` and `PluginMemberHandler` classes,
5
+ * which orchestrate CLI commands for lists of plugins and individual plugin operations.
6
+ *
7
+ * @module
8
+ */
9
+ import { Command } from "commander";
10
+ import { CLIoptions } from "../utils/cli.js";
11
+ /**
12
+ * Handles commands related to groups of ChRIS plugins.
13
+ */
14
+ export declare class PluginGroupHandler {
15
+ private baseGroupHandler;
16
+ private controller;
17
+ assetName: string;
18
+ constructor();
19
+ /**
20
+ * Displays an overview of the plugin system.
21
+ */
22
+ plugins_overview(): Promise<void>;
23
+ /**
24
+ * Lists plugin fields using the new command logic.
25
+ */
26
+ plugins_fields(): Promise<void>;
27
+ /**
28
+ * Deletes plugins using the new command logic.
29
+ * Supports batch deletion using ++ separator.
30
+ */
31
+ plugins_delete(searchable: string, options: CLIoptions): Promise<void>;
32
+ /**
33
+ * Adds a new plugin to ChRIS.
34
+ * @param image - The Docker image of the plugin.
35
+ * @param options - CLI options including public_repo and compute environments.
36
+ */
37
+ plugins_add(image: string, options: CLIoptions): Promise<void>;
38
+ /**
39
+ * Sets up the Commander.js commands for plugin group operations.
40
+ *
41
+ * @param program - The Commander.js program instance.
42
+ */
43
+ pluginGroupCommand_setup(program: Command): void;
44
+ }
45
+ /**
46
+ * Handles commands related to individual ChRIS plugins.
47
+ */
48
+ export declare class PluginMemberHandler {
49
+ private assetName;
50
+ private controller;
51
+ constructor();
52
+ /**
53
+ * Prints the content of a README file from a given repository URL.
54
+ * Attempts to fetch README.md or README.rst from 'master' or 'main' branches.
55
+ *
56
+ * @param repoUrl - The base URL of the plugin repository.
57
+ */
58
+ readme_print(repoUrl: string): Promise<void>;
59
+ /**
60
+ * Retrieves and displays the README for a specific plugin.
61
+ *
62
+ * @param pluginId - The ID of the plugin.
63
+ * @returns A Promise resolving to the documentation URL or null.
64
+ */
65
+ plugin_readme(pluginId: string): Promise<string | null>;
66
+ /**
67
+ * Retrieves a plugin ID based on search options.
68
+ *
69
+ * @param options - CLI options for searching for a plugin.
70
+ * @returns A Promise resolving to the plugin ID as a string, or null if not found.
71
+ */
72
+ pluginID_fromSearch(options: CLIoptions): Promise<string | null>;
73
+ /**
74
+ * Runs a plugin instance.
75
+ */
76
+ plugin_run(searchable: string, params: string): Promise<number | null>;
77
+ /**
78
+ * Resolves a search term to plugin IDs.
79
+ */
80
+ plugin_searchableToIDs(searchable: string): Promise<string[] | null>;
81
+ /**
82
+ * Sets up the Commander.js commands for individual plugin operations.
83
+ *
84
+ * @param program - The Commander.js program instance.
85
+ */
86
+ pluginCommand_setup(program: Command): void;
87
+ }
@@ -0,0 +1,303 @@
1
+ import { BaseGroupHandler } from "../handlers/baseGroupHandler.js";
2
+ import { table_display } from "../screen/screen.js";
3
+ import { PluginController } from "../controllers/pluginController.js";
4
+ import { Context, chrisContext, errorStack, errorStack_getAllOfType, Searchable } from "@fnndsc/cumin";
5
+ // import { plugins_fetchList, PluginListResult } from "../commands/plugins/list.js"; // No longer needed
6
+ import { pluginFields_fetch } from "../commands/plugins/fields.js";
7
+ import { plugins_searchByTerm, plugin_deleteById } from "../commands/plugins/delete.js";
8
+ import { prompt_confirm } from "../utils/ui.js";
9
+ import { plugin_add } from "../commands/plugins/add.js";
10
+ import { pluginsOverview_display } from "../commands/plugins/overview.js";
11
+ import { plugin_execute } from "../commands/plugin/run.js";
12
+ import { pluginIds_resolve } from "../commands/plugin/search.js";
13
+ import { pluginRun_render } from "../views/plugin.js"; // Still needed for pluginRun_render
14
+ import chalk from "chalk";
15
+ import { pluginReadme_render } from "../commands/plugin/readme.js";
16
+ /**
17
+ * Handles commands related to groups of ChRIS plugins.
18
+ */
19
+ export class PluginGroupHandler {
20
+ constructor() {
21
+ this.assetName = "plugins";
22
+ this.controller = PluginController.controller_create();
23
+ this.baseGroupHandler = new BaseGroupHandler(this.assetName, this.controller.chrisObject);
24
+ }
25
+ /**
26
+ * Displays an overview of the plugin system.
27
+ */
28
+ async plugins_overview() {
29
+ await pluginsOverview_display();
30
+ }
31
+ // /**
32
+ // * Lists plugins using the new command logic.
33
+ // */
34
+ // async plugins_list(options: CLIoptions): Promise<void> {
35
+ // try {
36
+ // const { plugins, selectedFields } = await plugins_fetchList(options);
37
+ // console.log(pluginList_render(plugins, selectedFields, { table: options.table, csv: options.csv }));
38
+ // } catch (error: unknown) {
39
+ // const msg = error instanceof Error ? error.message : String(error);
40
+ // console.error(msg);
41
+ // }
42
+ // }
43
+ /**
44
+ * Lists plugin fields using the new command logic.
45
+ */
46
+ async plugins_fields() {
47
+ try {
48
+ const fields = await pluginFields_fetch();
49
+ if (fields && fields.length > 0) {
50
+ table_display(fields, ["fields"]);
51
+ }
52
+ else {
53
+ console.log(`No resource fields found for ${this.assetName}.`);
54
+ }
55
+ }
56
+ catch (error) {
57
+ console.log(errorStack.stack_search(this.assetName)[0]);
58
+ }
59
+ }
60
+ /**
61
+ * Deletes plugins using the new command logic.
62
+ * Supports batch deletion using ++ separator.
63
+ */
64
+ async plugins_delete(searchable, options) {
65
+ const searchableObj = Searchable.from(searchable);
66
+ const searchables = searchableObj.toBatchSearchables();
67
+ for (const search of searchables) {
68
+ const items = await plugins_searchByTerm(search.raw);
69
+ if (items.length === 0) {
70
+ console.log(`No plugins found matching: ${search.raw}`);
71
+ continue;
72
+ }
73
+ for (const item of items) {
74
+ // Show item info - reusing table_display for single item details if possible, or simple log
75
+ console.log(`Preparing to delete Plugin: ID=${item.id}, Name=${item.name}, Version=${item.version}`);
76
+ if (!options.force) {
77
+ const confirmed = await prompt_confirm(`Are you sure you want to delete plugin ${item.name} (ID: ${item.id})?`);
78
+ if (!confirmed)
79
+ continue;
80
+ }
81
+ const success = await plugin_deleteById(item.id);
82
+ if (success) {
83
+ console.log(`Deleted plugin ${item.id}`);
84
+ }
85
+ else {
86
+ console.error(`Failed to delete plugin ${item.id}`);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ /**
92
+ * Adds a new plugin to ChRIS.
93
+ * @param image - The Docker image of the plugin.
94
+ * @param options - CLI options including public_repo and compute environments.
95
+ */
96
+ async plugins_add(image, options) {
97
+ await plugin_add(image, options);
98
+ }
99
+ /**
100
+ * Sets up the Commander.js commands for plugin group operations.
101
+ *
102
+ * @param program - The Commander.js program instance.
103
+ */
104
+ pluginGroupCommand_setup(program) {
105
+ // Manually set up commands to use new logic for list, but keep base for others
106
+ const pluginsCommand = program
107
+ .command(this.assetName)
108
+ .description(`Interact with a group of ChRIS ${this.assetName}`);
109
+ // Use base list command generator and add plugin-specific options
110
+ const listCommand = this.baseGroupHandler.baseListCommand_create(async (options) => {
111
+ await this.baseGroupHandler.resources_list(options);
112
+ });
113
+ listCommand.option("-a, --all", "List all plugins (disable pagination)");
114
+ pluginsCommand.addCommand(listCommand);
115
+ pluginsCommand
116
+ .command("fieldslist")
117
+ .description(`list the ${this.assetName} resource fields`)
118
+ .action(async () => {
119
+ await this.plugins_fields();
120
+ });
121
+ pluginsCommand
122
+ .command("delete <searchable>")
123
+ .description(`delete target ${this.assetName} resolved from '++' separated <searchable>, i.e. "id:77++id:33"`)
124
+ .option("-f, --force", `force the deletion without prompting for user confirmation`)
125
+ .action(async (searchable, options) => {
126
+ await this.plugins_delete(searchable, options);
127
+ });
128
+ pluginsCommand
129
+ .command("overview")
130
+ .description("Get an overview of various plugin-group operations")
131
+ .action(async (pluginId, options) => {
132
+ await this.plugins_overview();
133
+ });
134
+ pluginsCommand
135
+ .command("add <image>")
136
+ .description("Add a new plugin to ChRIS from a Docker image")
137
+ .option("-r, --public_repo <url>", "Public repository URL of the plugin (e.g., https://github.com/FNNDSC/pl-dcm2niix)")
138
+ .option("-c, --compute <names>", "Comma-separated list of compute resource names to assign the plugin to")
139
+ .option("--store <url>", "URL of the peer store to search/import from")
140
+ .option("--adminUser <username>", "Admin username for registration")
141
+ .option("--adminPassword <password>", "Admin password for registration")
142
+ .action(async (image, options) => {
143
+ await this.plugins_add(image, options);
144
+ });
145
+ }
146
+ }
147
+ /**
148
+ * Handles commands related to individual ChRIS plugins.
149
+ */
150
+ export class PluginMemberHandler {
151
+ constructor() {
152
+ this.assetName = "plugin";
153
+ this.controller = PluginController.controller_create();
154
+ }
155
+ /**
156
+ * Prints the content of a README file from a given repository URL.
157
+ * Attempts to fetch README.md or README.rst from 'master' or 'main' branches.
158
+ *
159
+ * @param repoUrl - The base URL of the plugin repository.
160
+ */
161
+ async readme_print(repoUrl) {
162
+ const content = await this.controller.readmeContent_fetch(repoUrl);
163
+ if (content) {
164
+ console.log(chalk.green.bold("\nREADME Content:"));
165
+ console.log(pluginReadme_render(content));
166
+ }
167
+ else {
168
+ console.log(chalk.red("README not found in the repository."));
169
+ }
170
+ }
171
+ /**
172
+ * Retrieves and displays the README for a specific plugin.
173
+ *
174
+ * @param pluginId - The ID of the plugin.
175
+ * @returns A Promise resolving to the documentation URL or null.
176
+ */
177
+ async plugin_readme(pluginId) {
178
+ try {
179
+ console.log(`Fetching info for plugin with ID: ${pluginId}`);
180
+ const documentation = await this.controller.documentationUrl_get(pluginId);
181
+ if (!documentation) {
182
+ return null;
183
+ }
184
+ console.log(documentation);
185
+ await this.readme_print(documentation);
186
+ return documentation;
187
+ }
188
+ catch (error) {
189
+ if (error instanceof Error) {
190
+ console.error(`Error fetching plugin info: ${error.message}`);
191
+ }
192
+ else {
193
+ console.error("An unknown error occurred while fetching plugin info");
194
+ }
195
+ }
196
+ return null;
197
+ }
198
+ /**
199
+ * Retrieves a plugin ID based on search options.
200
+ *
201
+ * @param options - CLI options for searching for a plugin.
202
+ * @returns A Promise resolving to the plugin ID as a string, or null if not found.
203
+ */
204
+ async pluginID_fromSearch(options) {
205
+ const pluginId = await this.controller.pluginID_fromSearch(options);
206
+ // Warning logic could be here if controller returns array, but controller returns single ID or null.
207
+ // Assuming single hit for simplicity based on previous refactor
208
+ return pluginId;
209
+ }
210
+ /**
211
+ * Runs a plugin instance.
212
+ */
213
+ async plugin_run(searchable, params) {
214
+ try {
215
+ const instance = await plugin_execute(searchable, params);
216
+ if (!instance) {
217
+ console.log(errorStack.messagesOfType_search("error", "plugin"));
218
+ return null;
219
+ }
220
+ console.log(pluginRun_render(instance));
221
+ return instance.id;
222
+ }
223
+ catch (e) {
224
+ const message = e instanceof Error ? e.message : String(e);
225
+ console.error(message);
226
+ return null;
227
+ }
228
+ }
229
+ /**
230
+ * Resolves a search term to plugin IDs.
231
+ */
232
+ async plugin_searchableToIDs(searchable) {
233
+ const hits = await pluginIds_resolve(searchable);
234
+ if (!hits) {
235
+ return null;
236
+ }
237
+ console.log(hits);
238
+ return hits;
239
+ }
240
+ /**
241
+ * Sets up the Commander.js commands for individual plugin operations.
242
+ *
243
+ * @param program - The Commander.js program instance.
244
+ */
245
+ pluginCommand_setup(program) {
246
+ const pluginCommand = program
247
+ .command(this.assetName)
248
+ .description(`Interact with a single ChRIS ${this.assetName}`);
249
+ if (pluginCommand) {
250
+ pluginCommand
251
+ .command("readme [pluginId]")
252
+ .description("Get the readme of a specific plugin")
253
+ .option("--search <searchString>", "Search for a plugin using a comma-separated key-value pair")
254
+ .action(async (pluginId, options) => {
255
+ let targetId;
256
+ if (pluginId === undefined) {
257
+ if (options.search === undefined) {
258
+ targetId = await chrisContext.current_get(Context.ChRISplugin); // Await and RPN change
259
+ }
260
+ else {
261
+ targetId = await this.pluginID_fromSearch(options);
262
+ }
263
+ }
264
+ else {
265
+ targetId = pluginId;
266
+ }
267
+ if (targetId) {
268
+ await this.plugin_readme(targetId);
269
+ }
270
+ else {
271
+ const warnings = errorStack_getAllOfType('warning');
272
+ if (warnings && warnings.length > 0) {
273
+ warnings.forEach(warning => console.error(chalk.yellow(warning)));
274
+ }
275
+ else {
276
+ console.error(chalk.red("Plugin not found."));
277
+ }
278
+ }
279
+ });
280
+ pluginCommand
281
+ .command("run <searchable...>")
282
+ .description("Run a plugin in a given context")
283
+ .allowUnknownOption(true)
284
+ .action(async (args, command) => {
285
+ const searchable = args[0];
286
+ let pluginParams = "";
287
+ if (args.length > 0) {
288
+ pluginParams = args.slice(1).join(" "); // Join with space
289
+ }
290
+ await this.plugin_run(searchable, pluginParams);
291
+ });
292
+ pluginCommand
293
+ .command("search <searchable>")
294
+ .description("Resolve a plugin searchable into an ID")
295
+ .action((searchable) => {
296
+ this.plugin_searchableToIDs(searchable);
297
+ });
298
+ }
299
+ else {
300
+ console.error(`Failed to find '${this.assetName}' command. The 'readme' subcommand was not added.`);
301
+ }
302
+ }
303
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file Handler for the plugin-meta command group.
3
+ *
4
+ * @module
5
+ */
6
+ import { Command } from "commander";
7
+ /**
8
+ * Handles commands related to groups of plugin metadata.
9
+ */
10
+ export declare class PluginMetaGroupHandler {
11
+ private baseGroupHandler;
12
+ private controller;
13
+ assetName: string;
14
+ constructor();
15
+ /**
16
+ * Sets up the Commander.js commands for plugin metadata group operations.
17
+ *
18
+ * @param program - The Commander.js program instance.
19
+ */
20
+ pluginMetaGroupCommand_setup(program: Command): void;
21
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @file Handler for the plugin-meta command group.
3
+ *
4
+ * @module
5
+ */
6
+ import { BaseGroupHandler } from "../handlers/baseGroupHandler.js";
7
+ import { PluginMetaController } from "../controllers/pluginMetaController.js";
8
+ /**
9
+ * Handles commands related to groups of plugin metadata.
10
+ */
11
+ export class PluginMetaGroupHandler {
12
+ constructor() {
13
+ this.assetName = "pluginMetas";
14
+ this.controller = PluginMetaController.controller_create();
15
+ this.baseGroupHandler = new BaseGroupHandler(this.assetName, this.controller.chrisObject);
16
+ }
17
+ /**
18
+ * Sets up the Commander.js commands for plugin metadata group operations.
19
+ *
20
+ * @param program - The Commander.js program instance.
21
+ */
22
+ pluginMetaGroupCommand_setup(program) {
23
+ this.baseGroupHandler.command_setup(program);
24
+ // The 'readme' command has been moved to pluginHandler.ts for consolidation.
25
+ // This handler can be extended with other plugin metadata specific commands in the future.
26
+ }
27
+ }