Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create parent directories when file doesn't exist with editor action. #356

Open
GrahamDumpleton opened this issue May 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@GrahamDumpleton
Copy link
Contributor

GrahamDumpleton commented May 6, 2024

Is your feature request related to a problem? Please describe.

When using the clickable action:

```editor:append-lines-to-file
file: ~/exercises/sample.txt
text: |
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
    do eiusmod tempor incididunt ut labore et dolore magna aliqua.
```

and the file doesn't exist, if parent directories also do not exist then file creation will fail.

Describe the solution you'd like

An option to the clickable action called something like makedirs which if set to true will result in parent directories being created if they do not exist.

Describe alternatives you've considered

First use a clickable action for a command to execute mkdir -p ... in the terminal to create parent directories.

In some respects making users create the directory hierarchy first themselves is more explicit, but there may be situations where it may be more appropriate to transparently create the directories, although one could use a hidden clickable action which automatically runs as well.

Additional information

No response

@GrahamDumpleton GrahamDumpleton added the enhancement New feature or request label May 6, 2024
@GrahamDumpleton
Copy link
Contributor Author

If using a clickable action for the terminal first, you would use:

```terminal:execute
command: mkdir -p ~/exercises/subdir
```

```editor:append-lines-to-file
file: ~/exercises/subdir/sample.txt
text: |
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
    do eiusmod tempor incididunt ut labore et dolore magna aliqua.
```

If you wanted the running of mkdir -p to be transparent, you would use:

```terminal:execute
prefix: Editor
title: Create file "~/exercises/subdir/sample.txt"
command: mkdir -p ~/exercises/subdir
cascade: true
description: |
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
    do eiusmod tempor incididunt ut labore et dolore magna aliqua.
```

```editor:append-lines-to-file
hidden: true
file: ~/exercises/subdir/sample.txt
text: |
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
    do eiusmod tempor incididunt ut labore et dolore magna aliqua.
```

This does rely on the terminal though, plus if focus was on the editor tab, it would flick back to the terminal tab to create any directories, and then once again flick back to the editor which is undesirable. One could avoid this by using a examiner:execute-test to run a supplied script in workshop/examiner/tests directory to create the directories first though and for that it would stay on the editor tab.

Problem with both of these is that a failure occurs in the editor clickable action you would not know as it is hidden.

Better approach therefore is a new option to allow creation of parent directories.

Rather than overload on editor:append-lines-to-file, may be better to add a new clickable action called editor:create-file which would fail if the file already exists, and which can create the parent directories (perhaps still optionally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

1 participant