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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user