mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Resolve relative ssh dir during config load on iOS
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
//go:build !ios
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/rwinkhart/libmutton/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Load loads libmuttoncfg.json and returns the configuration.
|
||||||
|
func Load() (*CfgT, error) {
|
||||||
|
cfgBytes, err := os.ReadFile(global.CfgPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("unable to load libmuttoncfg.json: " + err.Error())
|
||||||
|
}
|
||||||
|
var cfg CfgT
|
||||||
|
if err = json.Unmarshal(cfgBytes, &cfg); err != nil {
|
||||||
|
return nil, errors.New("unable to unmarshal libmuttoncfg.json: " + err.Error())
|
||||||
|
}
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
//go:build ios
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/rwinkhart/libmutton/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Load loads libmuttoncfg.json and returns the configuration.
|
||||||
|
func Load() (*CfgT, error) {
|
||||||
|
cfgBytes, err := os.ReadFile(global.CfgPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("unable to load libmuttoncfg.json: " + err.Error())
|
||||||
|
}
|
||||||
|
var cfg CfgT
|
||||||
|
if err = json.Unmarshal(cfgBytes, &cfg); err != nil {
|
||||||
|
return nil, errors.New("unable to unmarshal libmuttoncfg.json: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// iOS stores a relative path to account for the ever-changing app UUID
|
||||||
|
cfg.Libmutton.SSHKeyPath = new(global.SSHDir + *cfg.Libmutton.SSHKeyPath)
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
@@ -24,19 +24,6 @@ type CfgT struct {
|
|||||||
ClientSpecific *map[string]any `json:"clientSpecific"`
|
ClientSpecific *map[string]any `json:"clientSpecific"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads libmuttoncfg.json and returns the configuration.
|
|
||||||
func Load() (*CfgT, error) {
|
|
||||||
cfgBytes, err := os.ReadFile(global.CfgPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("unable to load libmuttoncfg.json: " + err.Error())
|
|
||||||
}
|
|
||||||
var cfg CfgT
|
|
||||||
if err = json.Unmarshal(cfgBytes, &cfg); err != nil {
|
|
||||||
return nil, errors.New("unable to unmarshal libmuttoncfg.json: " + err.Error())
|
|
||||||
}
|
|
||||||
return &cfg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write writes cfg to libmuttoncfg.json.
|
// Write writes cfg to libmuttoncfg.json.
|
||||||
// If used in append mode, any nil values in the
|
// If used in append mode, any nil values in the
|
||||||
// input cfg will be substituted with the existing values.
|
// input cfg will be substituted with the existing values.
|
||||||
Reference in New Issue
Block a user