Skip to content

Commit 14015ca

Browse files
dbtools-antcampoLeonSilva15
authored andcommitted
feat(generator): validate and wallet path provided in flag
Merge pull request validate_and_use_wallet_path_flag
1 parent 656b9ef commit 14015ca

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/index.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ const getWalletFileChoices = async () => {
174174
};
175175

176176

177+
// Prompts
178+
179+
const promptWalletPath = async () => {
180+
console.log( '\u001B[33m%s\u001B[0m', 'In order to unzip and copy the Wallet file, please ensure that you have file access permissions. \n' );
181+
182+
return await input(
183+
{
184+
// TODO: Cannot use tab to autocomplete, cannot use ~ for $HOME
185+
message: 'Please enter the path of your Oracle Wallet:',
186+
validate ( input ) {
187+
return checkIfDirectoryOrZip( input );
188+
}
189+
}
190+
);
191+
}
192+
177193
// Here we promisify the exec function from child_process to use it with async/await
178194
const execAsync = promisify( exec );
179195
export default class Generate extends Command {
@@ -300,6 +316,12 @@ export default class Generate extends Command {
300316

301317
// TODO: Validate and use wallet path
302318
const walletPathDirectory = flags['wallet-path'] ? flags['wallet-path'] : '';
319+
let walletPathValidationResult = undefined;
320+
321+
if (walletPathDirectory !== ''){
322+
walletPathValidationResult = checkIfDirectoryOrZip(walletPathDirectory);
323+
}
324+
303325

304326
// Ask the user for the application name.
305327
const appName = name === '' ? await input(
@@ -438,20 +460,18 @@ export default class Generate extends Command {
438460
connectionString: generateConnectionString( protocol, hostname, port, serviceValue )
439461
};
440462
} else {
441-
let walletPath;
442-
443-
console.log( '\u001B[33m%s\u001B[0m', 'In order to unzip and copy the Wallet file, please ensure that the read permissions have been given to the terminal. \n' );
463+
let walletPath = '';
444464

445-
walletPath = await input(
446-
{
447-
// TODO: Cannot use tab to autocomplete, cannot use ~ for $HOME
448-
message: 'Please enter your Cloud Wallet Path:',
449-
validate ( input ) {
450-
return checkIfDirectoryOrZip( input );
451-
}
465+
if(walletPathValidationResult === true){
466+
walletPath = walletPathDirectory;
467+
}
468+
else{
469+
if(walletPathValidationResult !== undefined){
470+
console.error('\u001B[31m%s\u001B[0m', walletPathValidationResult);
452471
}
453-
);
454472

473+
walletPath = await promptWalletPath();
474+
}
455475
// walletPath = createWalletDirectory( walletPath );
456476
walletPath = path.resolve( untildify( walletPath ) );
457477
walletDirectory = path.dirname( walletPath );

0 commit comments

Comments
 (0)