Dynamically updating configurations.yml
Introduction
On this page, we will cover the following:
- Adding a new dependent field to
exclude_file_ext
andfile
dynamic choice fields - Updating the local
template.json
to grab the new field - Using the newly added field
Step 1 - Adding a new dependent field to exclude_file_ext
and file
dynamic choice fields
The exclude_file_ext
dynamic choice command runs in the same directory as the workspace, which is why the output shows uip, vscode, cfg, and py
. To grab the file extensions in some other directory, we need a new field.
At the time of writing this document, the Controller does NOT allow setting the runtime directory when executing a dynamic choice command. To keep it consistent, the VSCode Plugin also doesn’t allow this. Thus, the best way to set a target directory is to add a new field and have exclude_file_ext
depend on it.
Using the UIP: Push All
command (See Extension Development), push the extension and template to the Controller. Once uploaded, add a new text field called target_directory
as shown below:
Then, double-click on the exclude_file_ext
field and set Text Field 2
as a dependent field:
Repeat the same for the file
field.
Step 2 - Updating the local template.json
to grab the new field
Now, go back to VSCode and run UIP: Pull
. You should see the following changes:
Whenever template.json
changes, the .schema
file under .uip/debug
also changes. .schema
is used by configurations.yml
to validate the field types, offer code-completion etc. In this case, updating template.json
results in some problems because exclude_file_ext
was changed to depend on target_directory
, but in configurations.yml
, we haven’t specified a value for it yet. Go ahead and add the target_directory
field (the value can be any directory, as long as it has some files in it) as shown below:
Step 3 - Using the newly added field
Make the following changes to list_of_file_extensions
method in extension.py
to use the new target_directory
field:
Now, press F5
(efe1
should still be the default) and it should hit the breakpoint. Let the dynamic choice command run to completion, and the output should show all the file extensions in target_directory
. In my case, the output is:
Now, let’s add a couple of configurations for the file
dynamic choice command, which will retrieve the list of files in target_directory
:
The list_all_files
configuration should list all the files in target_directory
whereas exclude_json_files
will list all files except the ones that end in .json
. You may have to change exclude_json_files
depending on the types of file that your target_directory
contains.
Modify the list_files
method in extension.py
to use the target_directory
as well:
Now, go ahead and launch list_all_files
:
Since a breakpoint wasn't set in list_files
, the debugger will attach and finish almost immediately. Upon completion, press Shift+Alt+3
, and you should see a listing of all the files in your target_directory.
Do the same with exclude_json_files
(or whatever you named it), and it should show all the files except the ones that end in .json
.