Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
foivospro committed Oct 3, 2024
2 parents 6e359b2 + e96e1e1 commit 3dbc4da
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 214 deletions.
2 changes: 1 addition & 1 deletion public/blocks/argumentBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var argumentBlock = {
text: 'argument' // default text for the input
}
],
extensions: ['restrict_argumentsCreate_to_argument'],
extensions: ['restrict_args_block'],
output: 'String',
style: 'Function inputs',
tooltip: '%{BKY_ARGUMENT_TOOLTIP}',
Expand Down
22 changes: 21 additions & 1 deletion public/blocks/lnBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,27 @@ 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]);
29 changes: 28 additions & 1 deletion public/blocks/mvBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,34 @@ 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]);
22 changes: 21 additions & 1 deletion public/blocks/rmBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,27 @@ 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]);
35 changes: 34 additions & 1 deletion public/blocks/sedBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,40 @@ var sedBlock = {
previousStatement: 'Action',
nextStatement: 'Action',
tooltip: '%{BKY_SED_TOOLTIP}',
helpUrl: '%{BKY_SED_HELPURL}' // URL to further information or documentation.
helpUrl: '%{BKY_SED_HELPURL}', // URL to further information or documentation.
generateCommand: function (block) {
let sedCommand = handleBlock(block); // Basic sed command

// Handle pattern and replacement
let patternBlock = block.getInputTargetBlock('regPattern');
let replacementText = block.getFieldValue('regReplaceText');

if (!patternBlock) {
console.error('Pattern block is missing');
return '';
}

let pattern = patternBlock.getFieldValue('regPattern');
if (typeof replacementText === 'undefined' || replacementText === '') {
console.error('Replacement text is missing or empty');
return '';
}

// Escape slashes in pattern and replacement
pattern = pattern.replace(/\//g, '\\/');
replacementText = replacementText.replace(/\//g, '\\/');
const hasGlobalFlag = block.getFieldValue('globally') === 'TRUE';

sedCommand = `sed -E 's/${pattern}/${replacementText}/${hasGlobalFlag ? 'g' : ''}'`;

let previousBlock = block.getPreviousBlock();
if (previousBlock && previousBlock.type === 'filenamesCreate') {
const filenames = handleFilenamesBlocks(previousBlock);
sedCommand += ` ${filenames}`;
}

generatedCommand = sedCommand;
}
};

Blockly.defineBlocksWithJsonArray([sedBlock]);
24 changes: 23 additions & 1 deletion public/blocks/touchBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,29 @@ 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
Loading

0 comments on commit 3dbc4da

Please sign in to comment.