cloud-pc-templates 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +149 -1
  2. package/package.json +4 -1
package/index.js CHANGED
@@ -1 +1,149 @@
1
- console.log('placeholder repo for coud-pc-templates.com');
1
+ #!/usr/bin/env node
2
+
3
+ // Command tree structure
4
+ const commandTree = {
5
+ help: {
6
+ description: 'Show help information',
7
+ handler: help
8
+ },
9
+ ai: {
10
+ description: 'Run AI operations',
11
+ handler: aiDefault,
12
+ subcommands: {
13
+ login: {
14
+ description: 'Login to AI service',
15
+ subcommands: {
16
+ loginMode: {
17
+ description: 'Specify login mode',
18
+ subcommands: {
19
+ ollamacloud: {
20
+ description: 'Connect to Ollama Cloud',
21
+ handler: () => aiLogin('ollamacloud')
22
+ },
23
+ ollamalocal: {
24
+ description: 'Connect to Ollama Local',
25
+ handler: () => aiLogin('ollamalocal')
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ };
34
+
35
+ // Help function
36
+ function help() {
37
+ console.log('Cloud PC Templates - Help');
38
+ console.log('');
39
+ console.log('Usage:');
40
+ console.log(' npx cloud-pc-templates Show this help message');
41
+ console.log(' npx cloud-pc-templates help Show this help message');
42
+ console.log(' npx cloud-pc-templates --help Show this help message');
43
+ console.log(' npx cloud-pc-templates ai Run AI function');
44
+ console.log('');
45
+ console.log('AI Commands:');
46
+ console.log(' npx cloud-pc-templates ai login loginMode ollamacloud');
47
+ console.log(' npx cloud-pc-templates ai login loginMode ollamalocal');
48
+ }
49
+
50
+ // Default AI function
51
+ function aiDefault() {
52
+ console.log('AI function - Use "npx cloud-pc-templates ai --help" for options');
53
+ }
54
+
55
+ // AI Login function
56
+ function aiLogin(mode) {
57
+ console.log(`✓ AI Login initialized with mode: ${mode}`);
58
+ if (mode === 'ollamacloud') {
59
+ console.log(' - Connecting to Ollama Cloud...');
60
+ console.log(' - Initializing cloud connection...');
61
+ } else if (mode === 'ollamalocal') {
62
+ console.log(' - Connecting to Ollama Local...');
63
+ console.log(' - Initializing local connection...');
64
+ }
65
+ }
66
+
67
+ // Function to show available options at a certain level
68
+ function showAvailableOptions(node, path) {
69
+ if (!node || !node.subcommands) {
70
+ return;
71
+ }
72
+
73
+ const pathStr = path.length > 0 ? path.join(' ') + ' ' : '';
74
+ console.log(`Available options for: npx cloud-pc-templates ${pathStr}`);
75
+ console.log('');
76
+
77
+ Object.entries(node.subcommands).forEach(([key, value]) => {
78
+ console.log(` ${key.padEnd(20)} - ${value.description || ''}`);
79
+ });
80
+ }
81
+
82
+ // Function to traverse command tree and execute or show options
83
+ function traverseCommandTree(args, startNode, startPath = []) {
84
+ let currentNode = startNode;
85
+ let path = startPath;
86
+
87
+ // Start from the second argument (first is already matched in processArgs)
88
+ for (let i = 1; i < args.length; i++) {
89
+ let arg = args[i].replace(/^--/, ''); // Remove -- prefix
90
+
91
+ // Check if current node has subcommands
92
+ if (currentNode.subcommands && currentNode.subcommands[arg]) {
93
+ currentNode = currentNode.subcommands[arg];
94
+ path.push(arg);
95
+ } else if (arg === 'help' || arg === '--help') {
96
+ showAvailableOptions(currentNode, path);
97
+ return;
98
+ } else {
99
+ console.log(`Unknown option: ${arg}`);
100
+ showAvailableOptions(currentNode, path);
101
+ return;
102
+ }
103
+ }
104
+
105
+ // At this point, we've traversed all provided arguments
106
+ // Check if we have subcommands available but user didn't provide all args
107
+ if (currentNode.subcommands) {
108
+ showAvailableOptions(currentNode, path);
109
+ } else if (currentNode.handler) {
110
+ // Execute the handler if available
111
+ currentNode.handler();
112
+ } else {
113
+ console.log('Command complete but no action defined');
114
+ }
115
+ }
116
+
117
+ // Main function to handle arguments
118
+ function processArgs() {
119
+ const args = process.argv.slice(2); // Remove node and script path
120
+
121
+ if (args.length === 0) {
122
+ help();
123
+ return;
124
+ }
125
+
126
+ // Get the first argument and remove any -- prefix
127
+ let command = args[0].replace(/^--/, '');
128
+
129
+ if (commandTree[command]) {
130
+ traverseCommandTree(args, commandTree[command], [command]);
131
+ } else {
132
+ console.log(`Unknown command: ${command}`);
133
+ help();
134
+ }
135
+ }
136
+
137
+ // Run if executed directly
138
+ if (require.main === module) {
139
+ processArgs();
140
+ }
141
+
142
+ // Export functions for use as a module
143
+ module.exports = {
144
+ help,
145
+ aiDefault,
146
+ aiLogin,
147
+ processArgs,
148
+ commandTree
149
+ };
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "cloud-pc-templates",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "cloud-pc-templates": "index.js"
8
+ },
6
9
  "scripts": {
7
10
  "test": "echo \"Error: no test specified\" && exit 1"
8
11
  },