Add config validation, remove command, status filtering, and unlock method display
config check: validates UUID format, recognized methods, keyfile consistency and existence. Reports all issues with alias context. remove: deletes a device from config by alias. Inverse of add. status: --mounted, --unlocked, --locked flags filter the device table. Flags combine as OR. mount/unlock: display which method succeeded and key slot used, e.g. "(fido2, key slot 1)". cryptsetup Open now runs with -v and parses "Key slot N unlocked" from stderr via io.MultiWriter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,12 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
filterMounted bool
|
||||
filterUnlocked bool
|
||||
filterLocked bool
|
||||
)
|
||||
|
||||
var statusCmd = &cobra.Command{
|
||||
Use: "status",
|
||||
Short: "Show LUKS volume status",
|
||||
@@ -17,6 +23,9 @@ var statusCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
statusCmd.Flags().BoolVar(&filterMounted, "mounted", false, "show only mounted devices")
|
||||
statusCmd.Flags().BoolVar(&filterUnlocked, "unlocked", false, "show only unlocked (but not mounted) devices")
|
||||
statusCmd.Flags().BoolVar(&filterLocked, "locked", false, "show only locked devices")
|
||||
rootCmd.AddCommand(statusCmd)
|
||||
}
|
||||
|
||||
@@ -34,6 +43,8 @@ func runStatus(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
filtering := filterMounted || filterUnlocked || filterLocked
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "DEVICE\tUUID\tALIAS\tSTATE\tMOUNTPOINT")
|
||||
|
||||
@@ -50,6 +61,23 @@ func runStatus(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if filtering {
|
||||
switch state {
|
||||
case "mounted":
|
||||
if !filterMounted {
|
||||
continue
|
||||
}
|
||||
case "unlocked":
|
||||
if !filterUnlocked {
|
||||
continue
|
||||
}
|
||||
case "locked":
|
||||
if !filterLocked {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
|
||||
dev.DevicePath, dev.UUID, alias, state, mountpoint)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user