mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
This splits the concern of how to display errors off from the business logic. This should make it easier to test functionality and allow us to concentrate on how to actually display and communicate errors to the user. At some point this might also make i18n feasible, because you only have to swap out a single file. This hasn't quite fixed the debug/trace story yet. It should be possible to simply insert a "debug" command into any pipeline and see the context and state at that point.
33 lines
1.1 KiB
Plaintext
Executable File
33 lines
1.1 KiB
Plaintext
Executable File
#!/usr/bin/env nu
|
|
|
|
use lib [eval-disko-file eval-flake exit-on-error print-info print-help]
|
|
|
|
def modes [] { ["destroy", "format", "mount", "format,mount", "destroy,format,mount"] }
|
|
|
|
|
|
def main [
|
|
mode: string@modes, # Mode to use. Allowed values are 'destroy', 'format', 'mount', 'format,mount', 'destroy,format,mount'
|
|
disko_file?: path, # File to read the disko configuration from. Can be a .nix file or a .json file
|
|
--flake (-f): string # Flake URI to search for the disko configuration
|
|
]: nothing -> nothing {
|
|
|
|
if not ($mode in (modes)) {
|
|
{
|
|
success: false,
|
|
messages: [ { code: ERR_INVALID_MODE, details: { mode: $mode, valid_modes: (modes) } } ]
|
|
} | exit-on-error "validate mode"
|
|
}
|
|
|
|
if not ($flake != null xor $disko_file != null) {
|
|
{ success: false, messages: [ { code: ERR_MISSING_ARGUMENTS } ] } | exit-on-error "validate arguments"
|
|
}
|
|
|
|
let config = if $disko_file != null {
|
|
$disko_file | eval-disko-file | exit-on-error "evaluate config"
|
|
} else {
|
|
$flake | eval-flake | exit-on-error "evaluate flake"
|
|
}
|
|
|
|
$config | to json | print-info
|
|
}
|