Skip to content

Commit

Permalink
Minor fixes in file handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
foivospro committed Oct 4, 2024
1 parent 85d365d commit 4bec880
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 75 deletions.
Binary file modified db/blockly_unix_database.db
Binary file not shown.
22 changes: 1 addition & 21 deletions public/blocks/lnBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,7 @@ var lnBlock = {
],
style: 'Filesystem Operations',
tooltip: '%{BKY_LN_TOOLTIP}',
helpUrl: 'https://linux.die.net/man/1/ln',
generateCommand: function (block) {
let lnCommand = 'ln ';
const symbolic = block.getFieldValue('symbolic') === 'TRUE';
const force = block.getFieldValue('force') === 'TRUE';
const interactive = block.getFieldValue('interactive') === 'TRUE';

if (symbolic) lnCommand += ' -s ';
if (force) lnCommand += ' -f ';
if (interactive) lnCommand += ' -i ';

const sourceArgsBlock = block.getInputTargetBlock('SOURCE');
const targetArgsBlock = block.getInputTargetBlock('TARGET');
lnCommand +=
handleArgumentsBlocks(sourceArgsBlock) +
' ' +
handleArgumentsBlocks(targetArgsBlock);

generatedCommand = lnCommand;
return generatedCommand;
}
helpUrl: 'https://linux.die.net/man/1/ln'
};

Blockly.defineBlocksWithJsonArray([lnBlock]);
29 changes: 1 addition & 28 deletions public/blocks/mvBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,7 @@ var mvBlock = {
],
style: 'Filesystem Operations',
tooltip: 'Μετακινεί ή μετονομάζει αρχεία.',
helpUrl: 'https://linux.die.net/man/1/mv',

generateCommand: function (block) {
let mvCommand = 'mv '; // Start the mv command

// Handle options
const notPromptConfirmation =
block.getFieldValue('not_prompt_confirmation') === 'TRUE';
const promptConfirmation =
block.getFieldValue('prompt_confirmation') === 'TRUE';
const notOverwrite = block.getFieldValue('not_overwrite') === 'TRUE';

if (notPromptConfirmation) mvCommand += '-f '; // Add -f for no prompt
if (promptConfirmation) mvCommand += '-i '; // Add -i for prompt
if (notOverwrite) mvCommand += '-n '; // Add -n for no overwrite

// Get source and destination blocks
const sourceArgsBlock = block.getInputTargetBlock('SOURCE');
const targetArgsBlock = block.getInputTargetBlock('DEST');

// Append arguments (source and destination paths)
mvCommand +=
handleArgumentsBlocks(sourceArgsBlock) +
' ' +
handleArgumentsBlocks(targetArgsBlock);

return mvCommand; // Return the generated mv command
}
helpUrl: 'https://linux.die.net/man/1/mv'
};

Blockly.defineBlocksWithJsonArray([mvBlock]);
22 changes: 1 addition & 21 deletions public/blocks/rmBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,7 @@ var rmBlock = {
extensions: [],
style: 'Filesystem Operations',
tooltip: '%{BKY_RM_TOOLTIP}',
helpUrl: 'https://linux.die.net/man/1/rm',

generateCommand: function (block) {
let rmCommand = 'rm ';
const force = block.getFieldValue('force') === 'TRUE';
const requestConfirmation =
block.getFieldValue('request_confirmation') === 'TRUE';
const removeDirectory = block.getFieldValue('remove_directory') === 'TRUE';
const recursive = block.getFieldValue('recursive') === 'TRUE';

if (force) rmCommand += '-f ';
if (requestConfirmation) rmCommand += '-i ';
if (removeDirectory) rmCommand += '-d ';
if (recursive) rmCommand += '-R ';

const argumentBlock = block.getInputTargetBlock('ARGUMENT');
rmCommand += ' ' + handleArgumentsBlocks(argumentBlock);

generatedCommand = rmCommand;
return generatedCommand;
}
helpUrl: 'https://linux.die.net/man/1/rm'
};

Blockly.defineBlocksWithJsonArray([rmBlock]);
8 changes: 3 additions & 5 deletions public/js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ function generateCommandFromWorkspace() {
var blockDef = window[currentBlock.type + 'Block'];
const specificCommand = handleSpecificBlocks(currentBlock);
try {
if (
if (filenameBlocks.includes(currentBlock.type)) {
console.log('Filename Block initiated');
} else if (
blockDef &&
(blockDef.category === 'I/O Redirection' ||
blockDef.category === 'Regular Expressions')
Expand All @@ -30,10 +32,6 @@ function generateCommandFromWorkspace() {
}
} catch (error) {
console.error('An error occurred:', error.message);
if (error.lineNumber) {
console.log('Line Number:', error.lineNumber);
}
console.error(error.stack);
break;
}
currentBlock = currentBlock.getNextBlock();
Expand Down

0 comments on commit 4bec880

Please sign in to comment.