Skip to content

Commit

Permalink
Added ability to overwrite VS Code settings (#175)
Browse files Browse the repository at this point in the history
This change adds the `visual_studio_code_settings_overwrite` property to the user configuration. By setting it to `yes` it will overwrite the VS Code settings file if it exists.

Co-authored-by: A. Tate Barber <[email protected]>
  • Loading branch information
freemanjp and tatemz authored Mar 8, 2020
1 parent 31e75cf commit 6ce59a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ users:
visual_studio_code_extensions:
- # extension 1
- # extension 2
visual_studio_code_settings_overwrite: # Overwrite the settings file if it exists. Options: boolean "yes" or "no" (defaults to "no").
visual_studio_code_settings: # JSON object
```
Expand All @@ -84,7 +85,7 @@ Minimal playbook:
- role: gantsign.visual-studio-code
```
Playbook with extensions installed:
Playbook with extensions installed that overwrites settings:
```yaml
- hosts: servers
Expand All @@ -96,6 +97,7 @@ Playbook with extensions installed:
- streetsidesoftware.code-spell-checker
- wholroyd.jinja
- ms-python.python
visual_studio_code_settings_overwrite: yes
visual_studio_code_settings: {
"editor.rulers": [80, 100, 120],
"editor.renderWhitespace": true,
Expand Down
19 changes: 19 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- test_usr
- test_usr2
- test_usr3
- test_usr4

- name: install gnupg2 (apt)
become: yes
Expand All @@ -36,6 +37,21 @@
state: present
when: ansible_pkg_mgr == 'apt'

- name: create settings directory
become: yes
become_user: test_usr4
file:
path: /home/test_usr4/.config/Code/User
state: directory
mode: 'u=rwx,go='

- name: install default settings
become: yes
become_user: test_usr4
copy:
content: '{"remove_me": true}'
dest: /home/test_usr4/.config/Code/User/settings.json

roles:
- role: ansible-role-visual-studio-code
users:
Expand All @@ -54,6 +70,9 @@
visual_studio_code_extensions: []
visual_studio_code_settings: {}
- username: test_usr3
- username: test_usr4
visual_studio_code_settings: {}
visual_studio_code_settings_overwrite: yes
- role: ansible-role-visual-studio-code
visual_studio_code_build: 'insiders'
users:
Expand Down
11 changes: 11 additions & 0 deletions molecule/default/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ def test_settings_insiders(host):
assert settings_file.group == 'test_usr'
assert settings_file.mode == 0o600
assert settings_file.contains('"Vagrantfile": "ruby"')


def test_settings_overwrite(host):
settings_file = host.file('/home/test_usr/.config/Code/User/settings.json')

assert settings_file.exists
assert settings_file.is_file
assert settings_file.user == 'test_usr'
assert settings_file.group == 'test_usr'
assert settings_file.mode == 0o600
assert not settings_file.contains('remove_me')
2 changes: 1 addition & 1 deletion tasks/write-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
template:
src: settings.json.j2
dest: '~{{ user.username }}/{{ visual_studio_code_config_path }}/User/settings.json'
force: no
force: '{{ user.visual_studio_code_settings_overwrite | default(False) | bool }}'
mode: 'u=rw,go='
with_items: '{{ users }}'
loop_control:
Expand Down

0 comments on commit 6ce59a4

Please sign in to comment.