Skip to content

Commit

Permalink
Fixes in filesystem operations blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
simosathan9 committed Oct 4, 2024
1 parent 8022fa1 commit 268390b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
19 changes: 18 additions & 1 deletion public/blocks/lnBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ var lnBlock = {
],
style: 'Filesystem Operations',
tooltip: '%{BKY_LN_TOOLTIP}',
helpUrl: 'https://linux.die.net/man/1/ln'
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;
}
};

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

Blockly.defineBlocksWithJsonArray([mvBlock]);
18 changes: 17 additions & 1 deletion public/blocks/rmBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,23 @@ var rmBlock = {
extensions: [],
style: 'Filesystem Operations',
tooltip: '%{BKY_RM_TOOLTIP}',
helpUrl: 'https://linux.die.net/man/1/rm'
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;
}
};

Blockly.defineBlocksWithJsonArray([rmBlock]);
22 changes: 21 additions & 1 deletion public/blocks/touchBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,27 @@ var touchBlock = {
extensions: ['validate_touch_time_d', 'restrict_touch_to_argumentsCreate'],
style: 'Filesystem Operations',
tooltip: '%{BKY_TOUCH_TOOLTIP}',
helpUrl: '%{BKY_TOUCH_HELPURL}' // URL to further information or documentation.
helpUrl: '%{BKY_TOUCH_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
let touchCommand = 'touch'; // Start with the basic touch command
// Check each option and append to the command if selected
const notCreateFile = block.getFieldValue('not_create_file') === 'TRUE';
const changeAccessTime = block.getFieldValue('access_time') === 'TRUE';
const changeModificationTime =
block.getFieldValue('modification_time') === 'TRUE';
const rawTimestamp = block.getFieldValue('change_time_d');
const argumentBlock = block.getInputTargetBlock('argument');
if (notCreateFile) touchCommand += ' -c';
if (changeAccessTime) touchCommand += ' -a';
if (changeModificationTime) touchCommand += ' -m';
if (rawTimestamp) {
const formattedTimestamp = rawTimestamp.replace(' ', 'T');
touchCommand += ` -d ${formattedTimestamp}`;
}
generatedCommand =
touchCommand + ' ' + handleArgumentsBlocks(argumentBlock);
return generatedCommand;
}
};

Blockly.defineBlocksWithJsonArray([touchBlock]);
Expand Down

0 comments on commit 268390b

Please sign in to comment.