|
27 | 27 |
|
28 | 28 | $ renku config registry https://registry.gitlab.com/demo/demo |
29 | 29 |
|
| 30 | +By default, configuration is stored locally in the project's directory. Use |
| 31 | +``--global`` option to store configuration for all projects in your home |
| 32 | +directory. |
| 33 | +
|
| 34 | +Remove values |
| 35 | +~~~~~~~~~~~~~ |
| 36 | +
|
| 37 | +To remove a specific key from configuration use: |
| 38 | +
|
| 39 | +.. code-block:: console |
| 40 | +
|
| 41 | + $ renku config --remove registry |
| 42 | +
|
| 43 | +By default, only local configuration is searched for removal. Use ``--global`` |
| 44 | +option to remove a global configuration value. |
| 45 | +
|
30 | 46 | Query values |
31 | 47 | ~~~~~~~~~~~~ |
32 | 48 |
|
33 | | -You display a previously set value with: |
| 49 | +You can display all configuration values with: |
| 50 | +
|
| 51 | +.. code-block:: console |
| 52 | +
|
| 53 | + $ renku config |
| 54 | +
|
| 55 | +Both local and global configuration files are read. Values in local |
| 56 | +configuration take precedence over global values. Use ``--local`` or |
| 57 | +``--global`` flag to read corresponding configuration only. |
| 58 | +
|
| 59 | +You can provide a KEY to display only its value: |
34 | 60 |
|
35 | 61 | .. code-block:: console |
36 | 62 |
|
37 | 63 | $ renku config registry |
38 | 64 | https://registry.gitlab.com/demo/demo |
39 | | -
|
40 | 65 | """ |
41 | 66 | import click |
42 | 67 |
|
43 | | -from renku.core.commands.config import update_config |
| 68 | +from renku.core import errors |
| 69 | +from renku.core.commands.config import read_config, update_config |
44 | 70 |
|
45 | 71 |
|
46 | 72 | @click.command() |
47 | | -@click.argument('key', required=True) |
| 73 | +@click.argument('key', required=False, default=None) |
48 | 74 | @click.argument('value', required=False, default=None) |
| 75 | +@click.option('--remove', is_flag=True, help='Remove specified key.') |
| 76 | +@click.option( |
| 77 | + '--local', |
| 78 | + 'local_only', |
| 79 | + is_flag=True, |
| 80 | + help='Read/store from/to local configuration only.' |
| 81 | +) |
49 | 82 | @click.option( |
50 | 83 | '--global', |
51 | | - 'is_global', |
| 84 | + 'global_only', |
52 | 85 | is_flag=True, |
53 | | - help='Store to global configuration.' |
| 86 | + help='Read/store from/to global configuration only.' |
54 | 87 | ) |
55 | | -def config(key, value, is_global): |
| 88 | +def config(key, value, remove, local_only, global_only): |
56 | 89 | """Manage configuration options.""" |
57 | | - updated = update_config(key, value, is_global) |
58 | | - click.secho(updated) |
| 90 | + is_write = value is not None |
| 91 | + |
| 92 | + if is_write and remove: |
| 93 | + raise errors.UsageError('Cannot remove and set at the same time.') |
| 94 | + if remove and not key: |
| 95 | + raise errors.UsageError('KEY is missing.') |
| 96 | + if local_only and global_only: |
| 97 | + raise errors.UsageError('Cannot use --local and --global together.') |
| 98 | + |
| 99 | + if remove: |
| 100 | + update_config(key, remove=remove, global_only=global_only) |
| 101 | + elif is_write: |
| 102 | + update_config(key, value=value, global_only=global_only) |
| 103 | + else: |
| 104 | + value = read_config(key, local_only, global_only) |
| 105 | + click.secho(value) |
0 commit comments