Set Command API Reference¶
This section documents the internals of the set
command in Bijux CLI.
bijux_cli.commands.config.set ¶
Implements the config set
subcommand for the Bijux CLI.
This module contains the logic for creating or updating a key-value pair in the active configuration store. It accepts input either as a direct argument or from stdin, performs strict validation on keys and values, and provides a structured, machine-readable response.
Output Contract
- Success:
{"status": "updated", "key": str, "value": str}
- Verbose: Adds
{"python": str, "platform": str}
to the payload. - Error:
{"error": str, "code": int}
Exit Codes
0
: Success.1
: An unexpected error occurred, such as a file lock or write failure.2
: An invalid argument was provided (e.g., malformed pair, invalid key).3
: The key, value, or configuration path contained non-ASCII or forbidden control characters.
set_config ¶
set_config(
ctx: Context,
pair: str | None = Argument(
None,
help="KEY=VALUE to set; if omitted, read from stdin",
),
quiet: bool = Option(
False, "-q", "--quiet", help=HELP_QUIET
),
verbose: bool = Option(
False, "-v", "--verbose", help=HELP_VERBOSE
),
fmt: str = Option(
"json", "-f", "--format", help=HELP_FORMAT
),
pretty: bool = Option(
True, "--pretty/--no-pretty", help=HELP_NO_PRETTY
),
debug: bool = Option(
False, "-d", "--debug", help=HELP_DEBUG
),
) -> None
Sets or updates a configuration key-value pair.
This function orchestrates the set
operation. It accepts a KEY=VALUE
pair from either a command-line argument or standard input. It performs extensive validation on the key and value for format and content, handles file locking to prevent race conditions, and emits a structured payload confirming the update.
Parameters:
-
ctx
(Context
) –The Typer context for the CLI.
-
pair
(str | None
, default:Argument(None, help='KEY=VALUE to set; if omitted, read from stdin')
) –A string in "KEY=VALUE" format. If None, the pair is read from stdin.
-
quiet
(bool
, default:Option(False, '-q', '--quiet', help=HELP_QUIET)
) –If True, suppresses all output except for errors.
-
verbose
(bool
, default:Option(False, '-v', '--verbose', help=HELP_VERBOSE)
) –If True, includes Python/platform details in the output.
-
fmt
(str
, default:Option('json', '-f', '--format', help=HELP_FORMAT)
) –The output format, "json" or "yaml".
-
pretty
(bool
, default:Option(True, '--pretty/--no-pretty', help=HELP_NO_PRETTY)
) –If True, pretty-prints the output.
-
debug
(bool
, default:Option(False, '-d', '--debug', help=HELP_DEBUG)
) –If True, enables debug diagnostics.
Returns:
-
None
(None
) –
Raises:
-
SystemExit
–Always exits with a contract-compliant status code and payload, indicating success or detailing the error.
Source code in src/bijux_cli/commands/config/set.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|