M8: add command to append a single device to config

New 'arca add <device>' subcommand detects a LUKS device via udisks2 and
appends it to the config with passphrase as default method. Supports
--alias/-a to override the generated name. Skips if UUID already
configured. Adds Config.Save() and Config.HasUUID() to config package.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 08:38:32 -07:00
parent 0c19f94292
commit feb22db039
3 changed files with 113 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
package config
import (
"fmt"
"os"
"path/filepath"
@@ -76,6 +77,31 @@ func resolvedFrom(dev DeviceConfig) ResolvedDevice {
}
}
// HasUUID returns true if a device with the given UUID is already configured.
func (c *Config) HasUUID(uuid string) bool {
for _, dev := range c.Devices {
if dev.UUID == uuid {
return true
}
}
return false
}
// Save writes the config to the config file.
func (c *Config) Save() error {
path := configPath()
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return fmt.Errorf("creating config directory: %w", err)
}
data, err := yaml.Marshal(c)
if err != nil {
return fmt.Errorf("marshaling config: %w", err)
}
return os.WriteFile(path, data, 0o644)
}
// AliasFor returns the config alias for a given UUID, or "" if none.
func (c *Config) AliasFor(uuid string) string {
for name, dev := range c.Devices {