Skip to content

Introduce gdk config set <key> <value>

Ash McKenzie requested to merge 939-introduce-gdk-config-set-key-value into main

What does this Merge Request do?

This MR adds support for gdk config set <key> <value>. When updating the gdk.yml, unfortunately formatting, ordering and comments are not retained and so we make a backup under GDK.root/.backups and advise the user.

Some examples:

Set string, integer and boolean

$ gdk config set port 3001
⚠️  WARNING: Your 'gdk.yml' is about to be re-written.
ℹ️  A backup will be saved at '/Users/ash/src/gitlab/gdks/gdk1/.backups/gdk.yml.20210430204435'.
ℹ️  port is now set to '3001' (previously '3002').

$ cat gdk.yml
---
port: 3001

$ gdk config set git.bin /usr/local/bin/new_git
⚠️  WARNING: Your 'gdk.yml' is about to be re-written.
ℹ️  A backup will be saved at '/Users/ash/src/gitlab/gdks/gdk1/.backups/gdk.yml.20210430204352'.
ℹ️  git.bin is now set to '/usr/local/bin/new_git' (previously '/usr/local/bin/git').

$ cat gdk.yml
---
port: 3001
git:
  bin: "/usr/local/bin/new_git"

$ gdk config set gdk.debug true
⚠️  WARNING: Your 'gdk.yml' is about to be re-written.
ℹ️  A backup will be saved at '/Users/ash/src/gitlab/gdks/gdk1/.backups/gdk.yml.20210430204417'.
ℹ️  gdk.debug is now set to 'true' (previously 'false').

$ cat gdk.yml
---
port: 3001
git:
  bin: "/usr/local/bin/new_git"
gdk:
  debug: true

$ gdk config set omniauth.github.enabled true
⚠️  WARNING: Your 'gdk.yml' is about to be re-written.
ℹ️  A backup will be saved at '/Users/ash/src/gitlab/gdks/gdk1/.backups/gdk.yml.20210430211957'.
ℹ️  'omniauth.github.enabled' is now set to 'true' (previously 'false').

$ cat gdk.yml
---
port: 3001
git:
  bin: "/usr/local/bin/new_git"
gdk:
  debug: true
omniauth:
  github:
    enabled: true

Detect setting the same value

$ gdk config set git.bin /usr/local/bin/new_git
ℹ️ git.bin is already set to '/usr/local/bin/new_git'.

$ gdk config set port 3001
ℹ️ port is already set to '3001'.

$ gdk config set gdk.debug true
ℹ️  gdk.debug is already set to 'true'.

Error handling

$ gdk config set
⚠️  WARNING: Usage: gdk config [<get>|set] <name> [<value>]

$ gdk config set git
⚠️  WARNING: Usage: gdk config [<get>|set] <name> [<value>]

$ gdk config set blah.blah false
❌️ ERROR: Cannot get config for 'blah.blah'.

$ gdk config set git false
❌️ ERROR: 'git' cannot be updated because its a settings block.

$ gdk config set git.bin false
❌️ ERROR: 'false' does not appear to be a valid Path.

$ gdk config set git.bin /tmp/bad
❌️ ERROR: '/tmp/bad' is a invalid value for 'git.bin'.

$ gdk config set port false
❌️ ERROR: 'false' does not appear to be a valid Integer.

$ gdk config set port test
❌️ ERROR: 'test' does not appear to be a valid Integer.

$ gdk config set gdk.debug test
❌️ ERROR: 'test' does not appear to be a valid Boolean.

Merge Request checklist

  • Tests added for new functionality. If not, please raise Issue to follow-up.
  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Documentation added/updated, if needed.
  • gdk doctor test added, if needed.

Closes #939 (closed)

Edited by Ash McKenzie

Merge request reports

Loading