aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/config.py
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-05-24 23:36:38 -0700
committerGitHub <noreply@github.com>2021-05-24 23:36:38 -0700
commitaa97f52963f3da6aa112093d357296e62bfa5452 (patch)
tree996629641891d8fddc9973a49200ca030dc995ea /lib/python/qmk/cli/config.py
parentbc67ca6a59ffa3d6e147b276c0544791e5f91d02 (diff)
downloadqmk_firmware-aa97f52963f3da6aa112093d357296e62bfa5452.tar.gz
qmk_firmware-aa97f52963f3da6aa112093d357296e62bfa5452.zip
Use milc.subcommand.config instead of qmk.cli.config (#13002)
* Use milc.subcommand.config instead * pyformat * remove the config test
Diffstat (limited to 'lib/python/qmk/cli/config.py')
-rw-r--r--lib/python/qmk/cli/config.py116
1 files changed, 0 insertions, 116 deletions
diff --git a/lib/python/qmk/cli/config.py b/lib/python/qmk/cli/config.py
deleted file mode 100644
index e17d8bb9b..000000000
--- a/lib/python/qmk/cli/config.py
+++ /dev/null
@@ -1,116 +0,0 @@
1"""Read and write configuration settings
2"""
3from milc import cli
4
5
6def print_config(section, key):
7 """Print a single config setting to stdout.
8 """
9 cli.echo('%s.%s{fg_cyan}={fg_reset}%s', section, key, cli.config[section][key])
10
11
12def show_config():
13 """Print the current configuration to stdout.
14 """
15 for section in cli.config:
16 for key in cli.config[section]:
17 print_config(section, key)
18
19
20def parse_config_token(config_token):
21 """Split a user-supplied configuration-token into its components.
22 """
23 section = option = value = None
24
25 if '=' in config_token and '.' not in config_token:
26 cli.log.error('Invalid configuration token, the key must be of the form <section>.<option>: %s', config_token)
27 return section, option, value
28
29 # Separate the key (<section>.<option>) from the value
30 if '=' in config_token:
31 key, value = config_token.split('=')
32 else:
33 key = config_token
34
35 # Extract the section and option from the key
36 if '.' in key:
37 section, option = key.split('.', 1)
38 else:
39 section = key
40
41 return section, option, value
42
43
44def set_config(section, option, value):
45 """Set a config key in the running config.
46 """
47 log_string = '%s.%s{fg_cyan}:{fg_reset} %s {fg_cyan}->{fg_reset} %s'
48 if cli.args.read_only:
49 log_string += ' {fg_red}(change not written)'
50
51 cli.echo(log_string, section, option, cli.config[section][option], value)
52
53 if not cli.args.read_only:
54 if value == 'None':
55 del cli.config[section][option]
56 else:
57 cli.config[section][option] = value
58
59
60@cli.argument('-ro', '--read-only', arg_only=True, action='store_true', help='Operate in read-only mode.')
61@cli.argument('configs', nargs='*', arg_only=True, help='Configuration options to read or write.')
62@cli.subcommand("Read and write configuration settings.")
63def config(cli):
64 """Read and write config settings.
65
66 This script iterates over the config_tokens supplied as argument. Each config_token has the following form:
67
68 section[.key][=value]
69
70 If only a section (EG 'compile') is supplied all keys for that section will be displayed.
71
72 If section.key is supplied the value for that single key will be displayed.
73
74 If section.key=value is supplied the value for that single key will be set.
75
76 If section.key=None is supplied the key will be deleted.
77
78 No validation is done to ensure that the supplied section.key is actually used by qmk scripts.
79 """
80 if not cli.args.configs:
81 return show_config()
82
83 # Process config_tokens
84 save_config = False
85
86 for argument in cli.args.configs:
87 # Split on space in case they quoted multiple config tokens
88 for config_token in argument.split(' '):
89 section, option, value = parse_config_token(config_token)
90
91 # Validation
92 if option and '.' in option:
93 cli.log.error('Config keys may not have more than one period! "%s" is not valid.', config_token)
94 return False
95
96 # Do what the user wants
97 if section and option and value:
98 # Write a configuration option
99 set_config(section, option, value)
100 if not cli.args.read_only:
101 save_config = True
102
103 elif section and option:
104 # Display a single key
105 print_config(section, option)
106
107 elif section:
108 # Display an entire section
109 for key in cli.config[section]:
110 print_config(section, key)
111
112 # Ending actions
113 if save_config:
114 cli.save_config()
115
116 return True