cli
napt.cli
Command-line interface for NAPT.
Commands:
init: Initialize a new NAPT project
validate: Validate recipe syntax and configuration
discover: Discover latest version and download installer
build: Build PSADT package from recipe
package: Create .intunewin package for Intune (recipe-based)
upload: Upload .intunewin package to Microsoft Intune
auth: Sign in to Microsoft Graph and inspect credentials
promote: Plan and apply deployment ring promotion
status: Show deployment state across all apps
Each command lives in its own module named after it (napt/cli/validate.py
owns napt validate), holding the command's cmd_* handlers and a
register(subparsers) hook that adds its parser. napt/cli/common.py
holds what every command shares: the output flags, the logger setup, and
the one error wrapper. napt/cli/main.py assembles the top-level parser,
calls each command's register, and dispatches to the selected handler
through that wrapper.
A command module imports the subsystem it drives inside its handler, not at
the top of the module, so building the parser for napt --help or
napt validate never loads the Azure or HTTP libraries.
Exit Codes:
- 0: Success
- 1: Error (configuration, download, or validation failure)
- 2: Usage error (unknown flag, missing argument)
- 130: Interrupted with Ctrl-C
Note
The CLI uses argparse for command parsing (stdlib, zero dependencies). Verbose mode shows full tracebacks on errors for debugging. Debug mode implies verbose mode and shows detailed configuration dumps.
napt.cli.main
CLI entry point: parser assembly and dispatch.
Builds the top-level napt argument parser, calls each command
module's register hook to add its subparser, and dispatches to the
selected command's handler. Registered as the napt console script in
pyproject.toml.
build_parser
Assembles the top-level parser with every command registered.
Returns:
| Type | Description |
|---|---|
ArgumentParser
|
The parser; parsing sets |
Source code in napt/cli/main.py
main
Main entry point for the napt CLI.
This function is registered as the 'napt' console script in pyproject.toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argv
|
list[str] | None
|
Arguments to parse instead of the process's own. |
None
|
Source code in napt/cli/main.py
napt.cli.common
What every napt command shares: flags, logger setup, errors, results.
A command module's register adds the shared flags with
add_output_flags and
add_state_dir; napt/cli/main.py calls
setup_logging once and runs the selected
handler through run_handler, so a handler
raises NAPT errors instead of catching them. A handler prints its result
through print_results, supplying the title,
the rows, and the success line.
EXIT_INTERRUPTED
module-attribute
Exit code for a run stopped with Ctrl-C: 128 plus SIGINT's signal number.
add_output_flags
Adds the -v/--verbose and -d/--debug flags to a command's parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
ArgumentParser
|
The command's (or subcommand's) parser. |
required |
Source code in napt/cli/common.py
add_state_dir
Adds the --state-dir override to a command's parser.
The flag is a path that defaults to None, which every command reads as
"use directories.state from configuration".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
ArgumentParser
|
The command's (or subcommand's) parser. |
required |
help_text
|
str
|
What the command does with the directory. |
required |
Source code in napt/cli/common.py
setup_logging
Configures the global logger from the parsed output flags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments carrying |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
The logger now installed as the global logger. |
Source code in napt/cli/common.py
print_results
print_results(
title: str,
rows: Iterable[tuple[str, object]],
success: str,
*,
failure: str | None = None
) -> None
Prints a command's results block.
The block is a banner, the title, one aligned Label: value line per
row, a closing banner, a blank line, and the success line. Labels pad to
the longest label in the block. A row whose value is None is left out,
so an optional field needs no branch in the handler. A command that
finished with partial results and will exit non-zero passes failure
and the block ends with [FAIL] instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Heading for the block (e.g., "BUILD RESULTS"). |
required |
rows
|
Iterable[tuple[str, object]]
|
Label and value pairs in display order. |
required |
success
|
str
|
What was accomplished, printed after |
required |
failure
|
str | None
|
What went wrong, printed after |
None
|
Source code in napt/cli/common.py
run_handler
Runs a command handler, reporting failures the same way for every command.
A NAPT error or an OS error becomes one line on stdout (with the traceback on stderr under -v or -d) and exit code 1; the label names authentication failures. Ctrl-C ends the run with exit code 130 and no traceback. Anything else is a bug and propagates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[Namespace], int]
|
The command's |
required |
args
|
Namespace
|
Parsed command-line arguments to hand to it. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The process exit code. |
Source code in napt/cli/common.py
napt.cli.auth
The napt auth command.
Manages the credential NAPT uses for Intune through the login,
logout, status, and setup subcommands.
cmd_auth_login
Handler for 'napt auth login' command.
Signs in interactively through the OS broker or the browser and caches the session so later commands authenticate silently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing optional client and tenant IDs and the --no-broker flag. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/auth.py
cmd_auth_logout
Handler for 'napt auth logout' command.
Removes the active tenant's cached session, or every tenant's with --all. Client and tenant IDs are kept for the next login.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing the --all flag and debug flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/auth.py
cmd_auth_status
Handler for 'napt auth status' command.
Shows which credential NAPT would use right now (the same resolution 'napt upload' performs) and flags missing Graph permissions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing debug flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 when a credential is available, 1 otherwise). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/auth.py
cmd_auth_setup
Handler for 'napt auth setup' command.
Creates or completes the NAPT app registration in a tenant through Microsoft Graph, or with --print-only prints the equivalent portal checklist without signing in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing the tenant ID, optional name, client ID, federated credential settings, and flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, 1 when an existing registration needs |
int
|
--adopt). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/auth.py
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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
register
Registers the 'auth' command parser and its subcommands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/auth.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
napt.cli.build
The napt build command.
Creates a PSADT deployment package from a recipe and a downloaded installer.
cmd_build
Handler for 'napt build' command.
Builds a PSADT package from a recipe and downloaded installer. This command loads the recipe configuration, reads the release to build from deployment state, finds the installer by its recorded hash, checks an MSI or MSIX version against its folder, downloads/caches the specified PSADT release, creates build directory structure, copies PSADT files pristine from cache, generates Invoke-AppDeployToolkit.ps1 with recipe values, copies installer to Files/ directory, and applies custom branding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing recipe path, downloads directory, output directory, and flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Creates build directory structure. Downloads PSADT release if not cached. Generates Invoke-AppDeployToolkit.ps1. Copies files to build directory. Prints progress and results to stdout. Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/build.py
register
Registers the 'build' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/build.py
napt.cli.discover
The napt discover command.
Finds the latest version of an application with the configured discovery strategy and downloads the installer.
cmd_discover
Handler for 'napt discover' command.
Discovers the latest version of an application by querying the source and downloading the installer. This command validates the recipe YAML, uses the configured discovery strategy to find the latest version, downloads the installer (or reuses the one an earlier run downloaded), extracts version information, and records the release as a pending publication candidate in deployment state when it differs from the published version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing recipe path, output directory, deployment state directory, and flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Downloads installer file to output_dir (or reuses an earlier download). Updates the app's deployment state file with the pending release. Prints progress and results to stdout. Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/discover.py
register
Registers the 'discover' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/discover.py
napt.cli.init
The napt init command.
Creates a new NAPT project structure with default configuration.
cmd_init
Handler for 'napt init' command.
Initializes a new NAPT project by creating the directory structure and default configuration files. This command creates the recipes/ directory, defaults/ directory with org.yaml template, defaults/vendors/ directory, and state/deployment/ directory for per-app deployment state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing directory path, force flag, and debug flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
By default, existing files are skipped (not overwritten). Use --force to backup existing files and create fresh ones. Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/init.py
register
Registers the 'init' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/init.py
napt.cli.package
The napt package command.
Packages a PSADT build into a .intunewin file for Intune deployment. The
build to package is the one for the release deployment state records
(pending, else published), the same release napt build built, so the
command never has to guess among the builds on disk.
cmd_package
Handler for 'napt package' command.
Creates a .intunewin package from a PSADT build for the given recipe. Packages the build of the release deployment state records, verifies it against the recorded installer hash, replaces that version's package folder, and copies the detection scripts alongside the .intunewin file so 'napt upload' is self-contained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing recipe path, version, directories, and debug flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Run 'napt build' before 'napt package'. Downloads IntuneWinAppUtil.exe if not cached. Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/package.py
register
Registers the 'package' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/package.py
napt.cli.promote
The napt promote command.
Plans and applies ring-based promotion of published apps through the
plan and apply subcommands.
cmd_promote_plan
Handler for 'napt promote plan' command.
Computes promotion actions for all recipes (or one recipe) as a pure function of deployment state, configuration, and the clock, and writes one plan file per app with work. Read-only with respect to Intune, and to deployment state unless --reconcile recovers a lost publication writeback first; an app's stale plan file is removed when none of its actions remain eligible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing the recipes path, state directory, and flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, with or without planned actions). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/promote.py
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 | |
cmd_promote_apply
Handler for 'napt promote apply' command.
Executes promotion plans against Intune: assigns install entries,
promotes releases through rings, displaces the older releases they
replace, and retires them per the retention policy. Executes only
the plan files written by napt promote plan, consuming each
per-app file after its app applies fully; with no plan file there
is nothing to apply. One app's failure keeps its plan file for
retry and never blocks the others, and stale or already-applied
actions are skipped with a warning, so re-running after a partial
failure is safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing the recipes path, state directory, plan file, and flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, including nothing to apply; |
int
|
1 when any app's plan failed to apply). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/promote.py
register
Registers the 'promote' command parser and its subcommands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/promote.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
napt.cli.status
The napt status command.
Aggregates per-app deployment state into one view: published version, pending release, and ring positions.
cmd_status
Handler for 'napt status' command.
Aggregates all per-app deployment state files into one view: the
published version, pending release, and which version holds each ring.
Without --state-dir, the directory comes from the recipes'
directories.state setting, the same one the pipeline wrote to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing the recipes path, state directory, output format, and flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/status.py
register
Registers the 'status' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/status.py
napt.cli.upload
The napt upload command.
Uploads the .intunewin package of the release recorded in deployment state for a recipe to Microsoft Intune via the Graph API.
cmd_upload
Handler for 'napt upload' command.
Uploads the .intunewin package of the release deployment state records (pending, else published) for a recipe to Microsoft Intune via the Graph API; with no recorded release, the only package. Authentication uses service principal / OIDC environment variables when set, otherwise the session saved by 'napt auth login'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing recipe path, directory overrides, and debug flags. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Run 'napt package' before this command to create the .intunewin file. Re-running an upload adopts existing NAPT-stamped apps instead of creating duplicates; --force re-sends metadata and content to them. Developers: run 'napt auth login' once. CI/CD: set AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_CLIENT_SECRET, or use OIDC federation. Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/upload.py
register
Registers the 'upload' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/upload.py
napt.cli.upstream
The napt upstream command: recipes imported from other git repositories.
napt upstream add imports upstream recipes from a repository as pinned
copies and writes the overrides that run them; napt upstream remove takes
one out again; napt upstream check reports which pinned copies drifted
from their upstream recipes and napt upstream update rewrites them. The
engines live in napt.upstream.add, napt.upstream.remove, and
napt.upstream.refresh; this module parses arguments and prints results.
cmd_upstream_add
Handler for 'napt upstream add'.
Imports the selected recipes from a repository: writes each one byte-identical as a pinned copy under upstream/, writes an override in recipes/ that names it as parent, and records each recipe's commit and hashes in upstream.yaml. Nothing is written if any recipe fails validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments carrying the clone URL, paths, ref, destination, id, exclude globs, and the dry-run flag. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/upstream.py
cmd_upstream_remove
Handler for 'napt upstream remove'.
Deletes a pinned copy and its lockfile entry, and the repository's entry once nothing of it remains. The override stays unless --delete-override is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments carrying the path and the delete-override flag. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success). |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/upstream.py
cmd_upstream_check
Handler for 'napt upstream check'.
Compares each pinned copy to the upstream recipe at the branch or tag tip and to its own lockfile entry, writing nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments carrying optional paths, the output format, and the exit-code flag. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code: 0 when the check completed; 1 with --exit-code when any |
int
|
recipe is changed or missing upstream. |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/upstream.py
cmd_upstream_update
Handler for 'napt upstream update'.
Rewrites the pinned copies whose upstream recipe changed, each with its own new commit in upstream.yaml; other entries keep their pins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments carrying optional paths, the output format, and the force flag. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code: 0 when every selected recipe was handled; 1 when a |
int
|
locally modified pinned copy was left alone. |
Note
Failures raise NAPT errors for run_handler to report.
Source code in napt/cli/upstream.py
register
Registers the 'upstream' command parser and its subcommands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |
Source code in napt/cli/upstream.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
napt.cli.validate
The napt validate command.
Checks a recipe's effective configuration (org.yaml, vendor defaults, parent, recipe) for syntax errors and configuration issues without downloading files or making network calls. Given a directory, checks every recipe under it and reports two files that resolve to the same id.
cmd_validate
Handler for 'napt validate' command.
Validates recipe syntax and configuration without downloading files or making network calls. This is useful for quick feedback during recipe development and for CI/CD pre-checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed command-line arguments containing the recipe or directory path and verbose flag. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 when every recipe is valid, 1 otherwise). |
Note
Prints validation results, errors, and warnings to stdout.
Source code in napt/cli/validate.py
register
Registers the 'validate' command parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subparsers
|
_SubParsersAction
|
The CLI's subparsers action to add the command to. |
required |