@f5-sales-demo/pi-resource-management 19.51.2

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/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@f5-sales-demo/pi-resource-management",
4
+ "version": "19.51.2",
5
+ "description": "Shared resource management for F5 XC manifest parsing, validation, diff, and CRUD operations",
6
+ "homepage": "https://github.com/f5-sales-demo/xcsh",
7
+ "author": "Robin Mordasiewicz",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/f5-sales-demo/xcsh.git",
12
+ "directory": "packages/resource-management"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/f5-sales-demo/xcsh/issues"
16
+ },
17
+ "keywords": [
18
+ "xcsh",
19
+ "resource-management",
20
+ "kubectl",
21
+ "apply",
22
+ "manifest"
23
+ ],
24
+ "main": "./src/index.ts",
25
+ "types": "./src/index.ts",
26
+ "scripts": {
27
+ "check": "biome check . && bun run check:types",
28
+ "check:types": "tsgo -p tsconfig.json --noEmit",
29
+ "generate-defaults": "bun run scripts/generate-defaults.ts && bun run fmt",
30
+ "lint": "biome lint .",
31
+ "test": "bun test",
32
+ "fix": "biome check --write --unsafe .",
33
+ "fmt": "biome format --write ."
34
+ },
35
+ "dependencies": {
36
+ "yaml": "2.9.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/bun": "^1.3"
40
+ },
41
+ "engines": {
42
+ "bun": ">=1.3.7"
43
+ },
44
+ "files": [
45
+ "src"
46
+ ],
47
+ "exports": {
48
+ ".": {
49
+ "types": "./src/index.ts",
50
+ "import": "./src/index.ts",
51
+ "require": "./src/index.ts",
52
+ "default": "./src/index.ts"
53
+ },
54
+ "./*": {
55
+ "types": "./src/*.ts",
56
+ "import": "./src/*.ts",
57
+ "require": "./src/*.ts"
58
+ },
59
+ "./*.js": "./src/*.ts"
60
+ }
61
+ }
@@ -0,0 +1,131 @@
1
+ import type { ParsedExportArgs, ParsedResourceArgs } from "./types";
2
+
3
+ const VALID_OUTPUT_FORMATS = new Set(["json", "yaml", "table", "wide"]);
4
+ const VALID_EXPORT_FORMATS = new Set(["json", "yaml"]);
5
+ const VALID_DRY_RUN_MODES = new Set(["client", "server"]);
6
+
7
+ export function parseResourceArgs(argsString: string): ParsedResourceArgs | { error: string } {
8
+ const tokens = argsString.split(/\s+/).filter(Boolean);
9
+ const filenames: string[] = [];
10
+ let namespace: string | undefined;
11
+ let outputFormat: ParsedResourceArgs["outputFormat"] = "table";
12
+ let dryRun: ParsedResourceArgs["dryRun"];
13
+ let recursive = false;
14
+ let force = false;
15
+ const positionals: string[] = [];
16
+
17
+ for (let i = 0; i < tokens.length; i++) {
18
+ const token = tokens[i];
19
+
20
+ if (token === "-f" || token === "--filename") {
21
+ if (i + 1 >= tokens.length) return { error: `${token} requires a file path.` };
22
+ filenames.push(tokens[++i]);
23
+ } else if (token.startsWith("-f") && token.length > 2 && token[2] !== "-") {
24
+ filenames.push(token.slice(2));
25
+ } else if (token === "-n" || token === "--namespace") {
26
+ if (i + 1 >= tokens.length) return { error: `${token} requires a namespace value.` };
27
+ namespace = tokens[++i];
28
+ } else if (token.startsWith("-n") && token.length > 2 && token[2] !== "-") {
29
+ namespace = token.slice(2);
30
+ } else if (token === "-o" || token === "--output") {
31
+ if (i + 1 >= tokens.length) return { error: `${token} requires a format value (json, yaml, table, wide).` };
32
+ const fmt = tokens[++i];
33
+ if (!VALID_OUTPUT_FORMATS.has(fmt)) {
34
+ return { error: `Invalid output format: "${fmt}". Must be one of: json, yaml, table, wide.` };
35
+ }
36
+ outputFormat = fmt as ParsedResourceArgs["outputFormat"];
37
+ } else if (token.startsWith("-o") && token.length > 2 && token[2] !== "-") {
38
+ const fmt = token.slice(2);
39
+ if (!VALID_OUTPUT_FORMATS.has(fmt)) {
40
+ return { error: `Invalid output format: "${fmt}". Must be one of: json, yaml, table, wide.` };
41
+ }
42
+ outputFormat = fmt as ParsedResourceArgs["outputFormat"];
43
+ } else if (token.startsWith("--dry-run")) {
44
+ if (token.includes("=")) {
45
+ const mode = token.split("=")[1];
46
+ if (!VALID_DRY_RUN_MODES.has(mode)) {
47
+ return { error: `Invalid --dry-run mode: "${mode}". Must be "client" or "server".` };
48
+ }
49
+ dryRun = mode as ParsedResourceArgs["dryRun"];
50
+ } else {
51
+ dryRun = "client";
52
+ }
53
+ } else if (token === "-R" || token === "--recursive") {
54
+ recursive = true;
55
+ } else if (token === "--force") {
56
+ force = true;
57
+ } else if (token.startsWith("-")) {
58
+ return { error: `Unknown flag: "${token}".` };
59
+ } else {
60
+ positionals.push(token);
61
+ }
62
+ }
63
+
64
+ return {
65
+ filenames,
66
+ namespace,
67
+ outputFormat,
68
+ dryRun,
69
+ recursive,
70
+ force,
71
+ kind: positionals[0],
72
+ name: positionals[1],
73
+ };
74
+ }
75
+
76
+ export function parseExportArgs(argsString: string): ParsedExportArgs | { error: string } {
77
+ const tokens = argsString.split(/\s+/).filter(Boolean);
78
+ let namespace: string | undefined;
79
+ let outputFormat: ParsedExportArgs["outputFormat"] = "json";
80
+ let outputFile: string | undefined;
81
+ let all = false;
82
+ const positionals: string[] = [];
83
+
84
+ for (let i = 0; i < tokens.length; i++) {
85
+ const token = tokens[i];
86
+
87
+ if (token === "-n" || token === "--namespace") {
88
+ if (i + 1 >= tokens.length) return { error: `${token} requires a namespace value.` };
89
+ namespace = tokens[++i];
90
+ } else if (token.startsWith("-n") && token.length > 2 && token[2] !== "-") {
91
+ namespace = token.slice(2);
92
+ } else if (token === "-o" || token === "--output") {
93
+ if (i + 1 >= tokens.length) return { error: `${token} requires a format value (json, yaml).` };
94
+ const fmt = tokens[++i];
95
+ if (!VALID_EXPORT_FORMATS.has(fmt)) {
96
+ return { error: `Invalid output format: "${fmt}". Must be one of: json, yaml.` };
97
+ }
98
+ outputFormat = fmt as ParsedExportArgs["outputFormat"];
99
+ } else if (token.startsWith("-o") && token.length > 2 && token[2] !== "-") {
100
+ const fmt = token.slice(2);
101
+ if (!VALID_EXPORT_FORMATS.has(fmt)) {
102
+ return { error: `Invalid output format: "${fmt}". Must be one of: json, yaml.` };
103
+ }
104
+ outputFormat = fmt as ParsedExportArgs["outputFormat"];
105
+ } else if (token === "-f" || token === "--file") {
106
+ if (i + 1 >= tokens.length) return { error: `${token} requires an output file path.` };
107
+ outputFile = tokens[++i];
108
+ } else if (token.startsWith("-f") && token.length > 2 && token[2] !== "-") {
109
+ outputFile = token.slice(2);
110
+ } else if (token === "--all") {
111
+ all = true;
112
+ } else if (token.startsWith("-")) {
113
+ return { error: `Unknown flag: "${token}".` };
114
+ } else {
115
+ positionals.push(token);
116
+ }
117
+ }
118
+
119
+ if (!all && positionals.length === 0) {
120
+ return { error: "Specify a resource kind, or use --all to export all resources." };
121
+ }
122
+
123
+ return {
124
+ kind: positionals[0],
125
+ name: positionals[1],
126
+ namespace,
127
+ outputFormat,
128
+ outputFile,
129
+ all,
130
+ };
131
+ }