puter-cli 1.7.1 → 1.7.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/CHANGELOG.md CHANGED
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [v1.7.2](https://github.com/HeyPuter/puter-cli/compare/v1.7.1...v1.7.2)
8
+
9
+ - fix: mv command for both rename/move files [`0b944c8`](https://github.com/HeyPuter/puter-cli/commit/0b944c8295f615427bd90d19a6058b2053c1b3dc)
10
+
7
11
  #### [v1.7.1](https://github.com/HeyPuter/puter-cli/compare/v1.7.0...v1.7.1)
8
12
 
13
+ > 4 March 2025
14
+
9
15
  - fix: update command [`38ca9e8`](https://github.com/HeyPuter/puter-cli/commit/38ca9e824642cbf8b1ffdb0d2a6e5426f84c7371)
10
16
  - docs: update README [`6e658f6`](https://github.com/HeyPuter/puter-cli/commit/6e658f6a117ee1ba206768905d53fb61c78e136d)
11
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puter-cli",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Command line interface for Puter cloud platform",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -117,54 +117,87 @@ export async function makeDirectory(args = []) {
117
117
  */
118
118
  export async function renameFileOrDirectory(args = []) {
119
119
  if (args.length < 2) {
120
- console.log(chalk.red('Usage: mv <old_name> <new_name>'));
120
+ console.log(chalk.red('Usage: mv <source> <destination>'));
121
121
  return;
122
122
  }
123
123
 
124
- const currentPath = getCurrentDirectory();
125
- const oldName = args[0];
126
- const newName = args[1];
124
+ const sourcePath = args[0].startsWith('/') ? args[0] : resolvePath(getCurrentDirectory(), args[0]);
125
+ const destPath = args[1].startsWith('/') ? args[1] : resolvePath(getCurrentDirectory(), args[1]);
127
126
 
128
- console.log(chalk.green(`Renaming "${oldName}" to "${newName}"...\n`));
127
+ console.log(chalk.green(`Moving "${sourcePath}" to "${destPath}"...\n`));
129
128
 
130
129
  try {
131
- // Step 1: Get the UID of the file/directory using the old name
130
+ // Step 1: Get the source file/directory info
132
131
  const statResponse = await fetch(`${API_BASE}/stat`, {
133
132
  method: 'POST',
134
133
  headers: getHeaders(),
135
- body: JSON.stringify({
136
- path: `${currentPath}/${oldName}`
137
- })
134
+ body: JSON.stringify({ path: sourcePath })
138
135
  });
139
136
 
140
137
  const statData = await statResponse.json();
141
138
  if (!statData || !statData.uid) {
142
- console.log(chalk.red(`Could not find file or directory with name "${oldName}".`));
139
+ console.log(chalk.red(`Could not find source "${sourcePath}".`));
143
140
  return;
144
141
  }
145
142
 
146
- const uid = statData.uid;
143
+ const sourceUid = statData.uid;
144
+ const sourceName = statData.name;
147
145
 
148
- // Step 2: Perform the rename operation using the UID
149
- const renameResponse = await fetch(`${API_BASE}/rename`, {
146
+ // Step 2: Check if destination is an existing directory
147
+ const destStatResponse = await fetch(`${API_BASE}/stat`, {
150
148
  method: 'POST',
151
149
  headers: getHeaders(),
152
- body: JSON.stringify({
153
- uid: uid,
154
- new_name: newName
155
- })
150
+ body: JSON.stringify({ path: destPath })
156
151
  });
157
152
 
158
- const renameData = await renameResponse.json();
159
- if (renameData && renameData.uid) {
160
- console.log(chalk.green(`Successfully renamed "${oldName}" to "${newName}"!`));
161
- console.log(chalk.dim(`Path: ${renameData.path}`));
162
- console.log(chalk.dim(`UID: ${renameData.uid}`));
153
+ const destData = await destStatResponse.json();
154
+
155
+ // Determine if this is a rename or move operation
156
+ const isMove = destData && destData.is_dir;
157
+ const newName = isMove ? sourceName : path.basename(destPath);
158
+ const destination = isMove ? destPath : path.dirname(destPath);
159
+
160
+ if (isMove) {
161
+ // Move operation: use /move endpoint
162
+ const moveResponse = await fetch(`${API_BASE}/move`, {
163
+ method: 'POST',
164
+ headers: getHeaders(),
165
+ body: JSON.stringify({
166
+ source: sourceUid,
167
+ destination: destination,
168
+ overwrite: false,
169
+ new_name: newName,
170
+ create_missing_parents: false,
171
+ new_metadata: {}
172
+ })
173
+ });
174
+
175
+ const moveData = await moveResponse.json();
176
+ if (moveData && moveData.moved) {
177
+ console.log(chalk.green(`Successfully moved "${sourcePath}" to "${moveData.moved.path}"!`));
178
+ } else {
179
+ console.log(chalk.red('Failed to move item. Please check your input.'));
180
+ }
163
181
  } else {
164
- console.log(chalk.red('Failed to rename item. Please check your input.'));
182
+ // Rename operation: use /rename endpoint
183
+ const renameResponse = await fetch(`${API_BASE}/rename`, {
184
+ method: 'POST',
185
+ headers: getHeaders(),
186
+ body: JSON.stringify({
187
+ uid: sourceUid,
188
+ new_name: newName
189
+ })
190
+ });
191
+
192
+ const renameData = await renameResponse.json();
193
+ if (renameData && renameData.uid) {
194
+ console.log(chalk.green(`Successfully renamed "${sourcePath}" to "${renameData.path}"!`));
195
+ } else {
196
+ console.log(chalk.red('Failed to rename item. Please check your input.'));
197
+ }
165
198
  }
166
199
  } catch (error) {
167
- console.log(chalk.red('Failed to rename item.'));
200
+ console.log(chalk.red('Failed to move/rename item.'));
168
201
  console.error(chalk.red(`Error: ${error.message}`));
169
202
  }
170
203
  }
@@ -206,7 +239,6 @@ async function findMatchingFiles(files, pattern, basePath) {
206
239
  return matchedPaths;
207
240
  }
208
241
 
209
-
210
242
  /**
211
243
  * Find files matching the pattern in the local directory (DEPRECATED: Not used)
212
244
  * @param {string} localDir - Local directory path.
@@ -1196,7 +1228,6 @@ async function resolveLocalDirectory(localPath) {
1196
1228
  return absolutePath;
1197
1229
  }
1198
1230
 
1199
-
1200
1231
  /**
1201
1232
  * Ensure a remote directory exists, creating it if necessary
1202
1233
  * @param {string} remotePath - The remote directory path