Skip to content

Commit eef38ee

Browse files
authored
Merge pull request #123 from internxt/fix/rename-typo-error
[_]: fix/rename-typo-error
2 parents e43ad6f + 64f9aec commit eef38ee

9 files changed

Lines changed: 560 additions & 250 deletions

File tree

README.md

Lines changed: 189 additions & 47 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"author": "Internxt <hello@internxt.com>",
3-
"version": "1.3.5",
3+
"version": "1.3.0",
44
"description": "Internxt CLI to manage your encrypted storage",
55
"scripts": {
66
"build": "tsc",
Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,44 @@
11
import { Command, Flags } from '@oclif/core';
22
import { ConfigService } from '../services/config.service';
3-
import { DriveFolderService } from '../services/drive/drive-folder.service';
43
import { CLIUtils } from '../utils/cli.utils';
5-
import {
6-
ItemNotFoundError,
7-
MissingCredentialsError,
8-
NotValidFolderUuidError,
9-
NotValidItemUuidError,
10-
} from '../types/command.types';
4+
import { MissingCredentialsError, NotValidFileUuidError, NotValidFolderUuidError } from '../types/command.types';
115
import { ValidationService } from '../services/validation.service';
126
import { DriveFileService } from '../services/drive/drive-file.service';
13-
import { DriveFileItem, DriveFolderItem } from '../types/drive.types';
147
import { ErrorUtils } from '../utils/errors.utils';
158

16-
export default class Move extends Command {
9+
export default class MoveFile extends Command {
1710
static readonly args = {};
18-
static readonly description = 'Move a folder/file into a destination folder.';
19-
11+
static readonly description = 'Move a file into a destination folder.';
12+
static readonly aliases = ['move:file'];
2013
static readonly examples = ['<%= config.bin %> <%= command.id %>'];
2114

2215
static readonly flags = {
2316
...CLIUtils.CommonFlags,
2417
id: Flags.string({
2518
char: 'i',
26-
description: 'The item id to be moved (it can be a file id or a folder id).',
19+
description: 'The file id to be moved.',
2720
required: false,
2821
}),
2922
destination: Flags.string({
3023
char: 'd',
31-
description: 'The destination folder id where the item is going to be moved.',
24+
description: 'The destination folder id where the file is going to be moved.',
3225
required: false,
3326
}),
3427
};
3528

3629
public async run() {
37-
const { flags } = await this.parse(Move);
30+
const { flags } = await this.parse(MoveFile);
3831

3932
const nonInteractive = flags['non-interactive'];
4033

4134
const userCredentials = await ConfigService.instance.readUser();
4235
if (!userCredentials) throw new MissingCredentialsError();
4336

44-
const itemUuid = await this.getItemUuid(flags['id'], nonInteractive);
37+
const fileUuid = await this.getFileUuid(flags['id'], nonInteractive);
4538
const destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
4639

47-
let item: DriveFileItem | DriveFolderItem | undefined;
48-
let isFolder = false;
49-
try {
50-
if (!item) {
51-
item = await DriveFileService.instance.getFileMetadata(itemUuid);
52-
isFolder = false;
53-
}
54-
} catch {
55-
/* noop */
56-
}
57-
try {
58-
if (!item) {
59-
item = await DriveFolderService.instance.getFolderMetaByUuid(itemUuid);
60-
isFolder = true;
61-
}
62-
} catch {
63-
/* noop */
64-
}
65-
66-
if (!item) throw new ItemNotFoundError();
67-
68-
if (isFolder) {
69-
await DriveFolderService.instance.moveFolder({ folderUuid: item.uuid, destinationFolderUuid });
70-
} else {
71-
await DriveFileService.instance.moveFile({ fileUuid: item.uuid, destinationFolderUuid });
72-
}
73-
CLIUtils.success(`${isFolder ? 'Folder' : 'File'} moved successfully to: ${destinationFolderUuid}`);
40+
await DriveFileService.instance.moveFile({ fileUuid, destinationFolderUuid });
41+
CLIUtils.success(`File moved successfully to: ${destinationFolderUuid}`);
7442
}
7543

7644
async catch(error: Error) {
@@ -79,21 +47,21 @@ export default class Move extends Command {
7947
this.exit(1);
8048
}
8149

82-
public getItemUuid = async (itemUuidFlag: string | undefined, nonInteractive: boolean): Promise<string> => {
83-
let itemUuid = CLIUtils.getValueFromFlag(
50+
public getFileUuid = async (fileUuidFlag: string | undefined, nonInteractive: boolean): Promise<string> => {
51+
let fileUuid = CLIUtils.getValueFromFlag(
8452
{
85-
value: itemUuidFlag,
86-
name: Move.flags['id'].name,
87-
error: new NotValidItemUuidError(),
53+
value: fileUuidFlag,
54+
name: MoveFile.flags['id'].name,
55+
error: new NotValidFileUuidError(),
8856
canBeEmpty: true,
8957
},
9058
nonInteractive,
91-
(itemUuid: string) => ValidationService.instance.validateUUIDv4(itemUuid),
59+
(fileUuid: string) => ValidationService.instance.validateUUIDv4(fileUuid),
9260
);
93-
if (!itemUuid) {
94-
itemUuid = (await this.getItemUuidInteractively()).trim();
61+
if (!fileUuid) {
62+
fileUuid = (await this.getFileUuidInteractively()).trim();
9563
}
96-
return itemUuid;
64+
return fileUuid;
9765
};
9866

9967
public getDestinationFolderUuid = async (
@@ -103,7 +71,7 @@ export default class Move extends Command {
10371
let destinationFolderUuid = CLIUtils.getValueFromFlag(
10472
{
10573
value: destinationFolderUuidFlag,
106-
name: Move.flags['destination'].name,
74+
name: MoveFile.flags['destination'].name,
10775
error: new NotValidFolderUuidError(),
10876
canBeEmpty: true,
10977
},
@@ -118,14 +86,14 @@ export default class Move extends Command {
11886

11987
private static readonly MAX_ATTEMPTS = 3;
12088

121-
public getItemUuidInteractively = (): Promise<string> => {
89+
public getFileUuidInteractively = (): Promise<string> => {
12290
return CLIUtils.promptWithAttempts(
12391
{
124-
message: 'What is the item id you want to move?',
92+
message: 'What is the file id you want to move?',
12593
options: { required: true },
126-
error: new NotValidItemUuidError(),
94+
error: new NotValidFileUuidError(),
12795
},
128-
Move.MAX_ATTEMPTS,
96+
MoveFile.MAX_ATTEMPTS,
12997
ValidationService.instance.validateUUIDv4,
13098
);
13199
};
@@ -137,7 +105,7 @@ export default class Move extends Command {
137105
options: { required: true },
138106
error: new NotValidFolderUuidError(),
139107
},
140-
Move.MAX_ATTEMPTS,
108+
MoveFile.MAX_ATTEMPTS,
141109
ValidationService.instance.validateUUIDv4,
142110
);
143111
};

src/commands/move-folder.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { Command, Flags } from '@oclif/core';
2+
import { ConfigService } from '../services/config.service';
3+
import { DriveFolderService } from '../services/drive/drive-folder.service';
4+
import { CLIUtils } from '../utils/cli.utils';
5+
import { MissingCredentialsError, NotValidFolderUuidError } from '../types/command.types';
6+
import { ValidationService } from '../services/validation.service';
7+
import { ErrorUtils } from '../utils/errors.utils';
8+
9+
export default class MoveFolder extends Command {
10+
static readonly args = {};
11+
static readonly description = 'Move a folder into a destination folder.';
12+
static readonly aliases = ['move:folder'];
13+
static readonly examples = ['<%= config.bin %> <%= command.id %>'];
14+
15+
static readonly flags = {
16+
...CLIUtils.CommonFlags,
17+
id: Flags.string({
18+
char: 'i',
19+
description: 'The folder id to be moved.',
20+
required: false,
21+
}),
22+
destination: Flags.string({
23+
char: 'd',
24+
description: 'The destination folder id where the folder is going to be moved.',
25+
required: false,
26+
}),
27+
};
28+
29+
public async run() {
30+
const { flags } = await this.parse(MoveFolder);
31+
32+
const nonInteractive = flags['non-interactive'];
33+
34+
const userCredentials = await ConfigService.instance.readUser();
35+
if (!userCredentials) throw new MissingCredentialsError();
36+
37+
const folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
38+
const destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
39+
40+
await DriveFolderService.instance.moveFolder({ folderUuid, destinationFolderUuid });
41+
CLIUtils.success(`Folder moved successfully to: ${destinationFolderUuid}`);
42+
}
43+
44+
async catch(error: Error) {
45+
ErrorUtils.report(error, { command: this.id });
46+
CLIUtils.error(error.message);
47+
this.exit(1);
48+
}
49+
50+
public getFolderUuid = async (folderUuidFlag: string | undefined, nonInteractive: boolean): Promise<string> => {
51+
let folderUuid = CLIUtils.getValueFromFlag(
52+
{
53+
value: folderUuidFlag,
54+
name: MoveFolder.flags['id'].name,
55+
error: new NotValidFolderUuidError(),
56+
canBeEmpty: true,
57+
},
58+
nonInteractive,
59+
(folderUuid: string) => ValidationService.instance.validateUUIDv4(folderUuid),
60+
);
61+
if (!folderUuid) {
62+
folderUuid = (await this.getFolderUuidInteractively()).trim();
63+
}
64+
return folderUuid;
65+
};
66+
67+
public getDestinationFolderUuid = async (
68+
destinationFolderUuidFlag: string | undefined,
69+
nonInteractive: boolean,
70+
): Promise<string> => {
71+
let destinationFolderUuid = CLIUtils.getValueFromFlag(
72+
{
73+
value: destinationFolderUuidFlag,
74+
name: MoveFolder.flags['destination'].name,
75+
error: new NotValidFolderUuidError(),
76+
canBeEmpty: true,
77+
},
78+
nonInteractive,
79+
(folderUuid: string) => ValidationService.instance.validateUUIDv4(folderUuid),
80+
);
81+
if (!destinationFolderUuid) {
82+
destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
83+
}
84+
return destinationFolderUuid;
85+
};
86+
87+
private static readonly MAX_ATTEMPTS = 3;
88+
89+
public getFolderUuidInteractively = (): Promise<string> => {
90+
return CLIUtils.promptWithAttempts(
91+
{
92+
message: 'What is the folder id you want to move?',
93+
options: { required: true },
94+
error: new NotValidFolderUuidError(),
95+
},
96+
MoveFolder.MAX_ATTEMPTS,
97+
ValidationService.instance.validateUUIDv4,
98+
);
99+
};
100+
101+
public getDestinationFolderUuidInteractively = (): Promise<string> => {
102+
return CLIUtils.promptWithAttempts(
103+
{
104+
message: 'What is the destination folder id?',
105+
options: { required: true },
106+
error: new NotValidFolderUuidError(),
107+
},
108+
MoveFolder.MAX_ATTEMPTS,
109+
ValidationService.instance.validateUUIDv4,
110+
);
111+
};
112+
}

src/commands/rename.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export default class Rename extends Command {
2323
...CLIUtils.CommonFlags,
2424
id: Flags.string({
2525
char: 'i',
26-
description: 'The item id to be renamed (it can be a file id or a folder id).',
26+
description: 'The ID of the item to rename (can be a file ID or a folder ID).',
2727
required: false,
2828
}),
2929
name: Flags.string({
3030
char: 'n',
31-
description: 'The new item name that the item is going to be have.',
31+
description: 'The new name for the item.',
3232
required: false,
3333
}),
3434
};

0 commit comments

Comments
 (0)